Help with Boolean Logic
soccerboy
Posts: 2
How can I get a BS2 to recognize negative values while using boolean logic. Here is an example:
X VAR Word
X = -2
If (X > 2) THEN DEBUG "Hello"
This code in my BS2 will still return Hello.
Thanks
X VAR Word
X = -2
If (X > 2) THEN DEBUG "Hello"
This code in my BS2 will still return Hello.
Thanks
Comments
· IF (x.BIT15 = 0) AND (x > 2) THEN
··· DEBUG "Hello"
· ENDIF
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
You do the twos compliment by converting the decimal number to binary then logically NOT each bit and add 1.
2 = 0000000000000010
NOT 2 = 1111111111111101
add 1 = 1111111111111110
Converting this to Hex, 1111 1111 1111 1110, you get $FFFE.
Larry
X = -2
Y = 2
If (X+32768 > Y+32768) THEN DEBUG "Hello"
Plug in a few numbers for X and Y to get a feel for how it works. The Stamp happily works with + numbers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Ryan