XORs r' us


Closed Thread
Results 1 to 5 of 5

Thread: XORs r' us

  1. #1
    Join Date
    Mar 2010
    Location
    Austin, TX
    Posts
    68

    Default XORs r' us

    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?
    PickyBiker says, "Riding a motorcycle eases programming frustration".

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    A single caret ^ is a Bitwise operator.

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

    hth,
    DT

  3. #3
    Join Date
    Mar 2010
    Location
    Austin, TX
    Posts
    68


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrell. It makes sense now.

    Lost a couple hours on that one.
    PickyBiker says, "Riding a motorcycle eases programming frustration".

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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>
    DT

  5. #5
    Join Date
    Mar 2010
    Location
    Austin, TX
    Posts
    68


    Did you find this post helpful? Yes | No

    Default

    Gone for a ride. Maybe tomorrow as well.
    PickyBiker says, "Riding a motorcycle eases programming frustration".

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts