PDA

View Full Version : XORs r' us



PickyBiker
- 9th April 2010, 23:24
Okay, the following 2 examples provide different answers. Why?

'correct according to the book, (^^ = XOR) but wrong answer
' it results in rb_change being $ff always

rb_change = rb_read ^^ rb_save


' wrong according to the book, (^ = nothing) but right answer, rb_change becomes an xor of the two variables

rb_change = rb_read ^ rb_save


Here is the acutal code:
while 1 ; continue forever
rb_read = portb >> 4 ' get the 4 inputs into the right nibble
rb_channel_change = rb_read ^ rb_save ' if one changed, get it into rb_channel_change
rb_save = rb_read ' save the data for the next time around
if rb_channel_change then
gosub test_change ' a channel changed
endif
wend


What am I missing?

Darrel Taylor
- 9th April 2010, 23:37
A single caret ^ is a Bitwise operator.

Double caret ^^ is a logical operator resulting in a True or False answer.

hth,

PickyBiker
- 9th April 2010, 23:46
Thanks Darrell. It makes sense now.

Lost a couple hours on that one.

Darrel Taylor
- 9th April 2010, 23:57
Just a couple hours?

Crap, I thought that would have been frustrating enough to warrant a ride on the bike.
Oh well, tomorrows Saturday, that's good for a ride even when not frustrated. :)
<br>

PickyBiker
- 10th April 2010, 00:15
Gone for a ride. Maybe tomorrow as well.