Searching \ for 'Whats the difference between IF true and NOT' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=whats+difference
Search entire site for: 'Whats the difference between IF true and NOT'.

Truncated match.
PICList Thread
'Whats the difference between IF true and NOT'
1998\05\08@002227 by PHXSYS

picon face
Hello

According to the stamp manual page 274, if I understand it you can write an
If...then statement like:

Flag     var    byte
Flag  =  1

If flag then  istrue          'Value is true- True is any value other than 0
    and
If NOT flag then istrue    'Is also true

Isn't NOT 1 the same as 0 or 2...any non 0 number. If true is any value other
than 0 and "NOT 1 is true" as well as any non-zero numberI don't understand
the difference.

For example whats the difference between these two commands

IF NOT in1 then si2c_rbyte_dl
   and
IF bit_count then si2c_rbyte_lp


Thanks

Jon

1998\05\08@034603 by Bill Cornutt

flavicon
face
Jon,

The short answer.

Use the value -1 for true instead of 1,2 or anyother value.

NOT -1 = 0
NOT 0 = -1

end of short answer.

Long answer.

Operators like AND, OR, EXCLUSIVE OR, and NOT
can come in two varities.  Logical and bitwise.
Because they react differently you have to use
the right one with higher level languages.

I think your problem is that you are thinking
logicaly and the Stamp basic is working
bitwise.

Note.... the bitwise type of operator should
not be confused with operations on a specific
bit in a byte like the pic can preform.

Bitwise means that every bit in the byte or
variable is operated on.  And this may be what
the Stamp basic uses.  So the following applies
to the operator functioning in a bitwise manner.

False means that all bits in the byte or variable
are off.  True means that all bits in byte or
variable are not off. (at least one bit in the
byte or variable is on)

The NOT operator complements the byte (or variable).
So that every bit that was on before the NOT is
off after the NOT.  And every bit that was off before
the NOT, is on after the NOT.

I keep saying byte or variable because in some
languages a integer is two bytes long.  And
I don't know how many butes the Stamp uses
for a variable.

If you NOT 0 then the results will be all
bits on, or the value -1.  And if you NOT
the value -1 then the results will be all
bits off, or 0.  This is why it is best to
use -1 as the TRUE value when setting flags.
It is not necessary, but when you start
NOT'ing them, they will work properly.
<properly if you are thinking logicaly>

With any value other than 0 or -1, the NOT will
just toggle all the bits and some will toggle
on and the rest will toggle off.  But in the
end, the result will allways have one or more
bits on and be considered TRUE.

If you NOT the value of 1, then all bits are
on except the Least Signifuenct Bit 'LSB".
And this will show as a value of -2.

Now a question.

What does 1 AND 2 return?
And how about 1 OR 2?

Have fun,

Bill C.    spam_OUTbillTakeThisOuTspamcornutt.com


----------
{Quote hidden}

1998\05\08@080407 by Caisson

flavicon
face
> Van: PHXSYS <.....PHXSYSKILLspamspam@spam@AOL.COM>
> Aan: PICLISTspamKILLspamMITVMA.MIT.EDU
> Onderwerp: Whats the difference between IF true and NOT
> Datum: vrijdag 8 mei 1998 5:59
>
> Hello
>
> According to the stamp manual page 274, if I understand it you can write
an
> If...then statement like:
>
> Flag     var    byte
> Flag  =  1
>
> If flag then  istrue          'Value is true- True is any value other
than 0
>      and
> If NOT flag then istrue    'Is also true
>
> Isn't NOT 1 the same as 0 or 2...any non 0 number. If true is any value
other
> than 0 and "NOT 1 is true" as well as any non-zero numberI don't
understand
{Quote hidden}

Try to look at it this way :

True & False are _logical_ variables (1 Bit wide). You can represent them
as you like, as is done here : 0 == True, all other values are False.  So,
first convert your register-value (256 states, 0 thru 255) to a Logical
state (2 states, True or False)

Now let's look at your question :

 if <var> then <action>

If <var> is 0 it is True and the <action> will be taken.  If <var> contains
anything else it will not.

Now the next :

 if NOT <var> then <action>

If <var> is 0 it is True. This will be _logically_ inverted (NOT).  This
makes the
result False.  The <action> will _not_ be taken.

If <var> is not equal to 0 it is False.  Invert it and you get True.  The
<action> will be taken ...

The example 'IF bit_count then si2c_rbyte_lp'  is dirty piece of code.  Why
? because we use a register that should hold only 2-state's (True & False)
as a
counter (256 states for  Byte-counter).  It works fine because if the
counter == 0 it will _logically_ be equal to a True.  If the counter is
anything else than a 0 it will, again logically, be equal to a False.

Greetz,
 Rudy Wieser

1998\05\09@024132 by PHXSYS

picon face
BILL

THANKS FOR THE LONG ANSWER


JON

1998\05\09@025213 by PHXSYS
picon face
In a message dated 98-05-08 08:04:10 EDT, you write:

<< The example 'IF bit_count then si2c_rbyte_lp'  is dirty piece of code.  Why
? because we use a register that should hold only 2-state's (True & False)
as a
counter (256 states for  Byte-counter).  It works fine because if the
counter == 0 it will _logically_ be equal to a True.  If the counter is
anything else than a 0 it will, again logically, be equal to a False.

Greetz,
  Rudy Wieser

 >>
THANK YOU FOR YOUR TIME, BUT I AM REALLY CONFUSED NOW. I WILL STUDY YOUR
EXPLANATION IN DETAIL. I THOUGHT IF BIT_COUNT WAS ANY VALUE OTHER THAN 0 IT IS
TRUE AND WILL BRANCH

'IF bit_count then si2c_rbyte_lp'

JON

1998\05\09@032819 by PHXSYS

picon face
In a message dated 98-05-08 08:04:10 EDT, you write:

<< if <var> then <action>

If <var> is 0 it is True and the <action> will be taken.  If <var> contains
anything else it will not.
 >>

I thought any value other than 0 makes this statement true. What am I missing?

Jon

1998\05\09@071405 by Bill Cornutt

flavicon
face
----------
> In a message dated 98-05-08 08:04:10 EDT, you write:
>
> << if <var> then <action>
>
>  If <var> is 0 it is True and the <action> will be taken.  If <var> contains
>  anything else it will not.
>   >>
>
> I thought any value other than 0 makes this statement true. What am I missing?
>
> Jon
>

Jon,

There does seem to be some confussion.

The final word can only come from the program.
When you don't know how something works or when
something isn't working like you think it should,
it is time to find out what the program thinks (and
does),

The way to do this is to write a simple, small program
who's only job is to see what the code in question is
doing.  If your DOS has QBasic, then this is a good
language in which to write test programs.  Or if you
can test it with the Stamp basic, then that is more
certain.  When you are playing with logic operators
I would suggest that you display your input and output
in binary,  This will help you see what is going on with

the program.

You show a lot of promise in that you found the code in
your program that wasn't working like yor thought it should
and you did some testing to see what it was doing.  Then you
posted a question with just the troubled code and stated
your question in a clear manner.  Now it may be time to
play with the code in question and find what it does  under
various inputs.  With this knowledge you will be able to
develop your own 'rules'.

As for what makes a TRUE value, when I read the post that
stated that TRUE was 0, I thought I had bade a big bobo.
Then I looked at your post and seen what you said TRUE was
and thought that this had influenced me and caused me to
give the wrong value for TRUE.  The thing is that it is
easy to think one thing and say another or just get things
wrong.  And one should NEVER ignore the possibility that
they are wrong.

So what is a TRUE value?  What does the book say?  Does the
assembler, compiler or interputer work like the book says?
Yes, it is like the guy who said "I wish the person who drew
the cover had wrote the book."  So the assembler, compiler,
interpeter may have a bug.

Bill C.  .....billKILLspamspam.....cornutt.com

1998\05\11@064036 by Caisson

flavicon
face
> Van: PHXSYS <EraseMEPHXSYSspam_OUTspamTakeThisOuTAOL.COM>
> Aan: PICLISTspamspam_OUTMITVMA.MIT.EDU
> Onderwerp: Re: Whats the difference between IF true and NOT
> Datum: zaterdag 9 mei 1998 8:50
>
> In a message dated 98-05-08 08:04:10 EDT, you write:
>
> << The example 'IF bit_count then si2c_rbyte_lp'  is dirty piece of code.
Why
>  ? because we use a register that should hold only 2-state's (True &
False)
{Quote hidden}

IT IS
> TRUE AND WILL BRANCH
>
>  'IF bit_count then si2c_rbyte_lp'
>
> JON

Akk...  I have mixed-up the True & False states.  Just read 'False' where I
wrote 'True' and 'True' where I used 'False'.   Sorry for this part of the
confusion.

Greetz,
 Rudy Wieser

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...