Results 1 to 4 of 4

Thread: Xor bitwise expression

  1. #1

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316
    I was given some code that uses Xor and was trying to figure out how it does what it does. I understand the whole logical comparison of true and true is false and false and false is false but false and true is true. HOWEVER, I don't quite comprehend what a bitwise comparison is... why is 104 Xor 50 = 90 ??? Could someone explain it to me. Thanks.
    SCUZ

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Think of it as a switch

    Xor switches bits. If a bit is in both operands, then the result will not have that bit set. If a bit is in only one operand, then the result will have the bit set.

    Code:
    so, in binary: 
    OOOOOOO1 XOR 
    OOOOOO1O          (i.e. 1 Xor 2 in decimal)
    ========
    OOOOOO11           =3
    
    In your example:
    O11O1OOO XOR       =104
    O1O11O1O           = 90
    ========
    OO11OO1O           = 50
    Does it help? Or is it more confusing now?

    Cheers

    P.S> Both Megatron and I are posting help but the darn forum messes with the formatting...

    [Edited by PaulLewis on 10-02-2000 at 05:55 PM]
    Paul Lewis

  3. #3
    Guest
    If you understand how it manipulates the bits, then you should have no trouble understanding this.
    Code:
    1101000            <- 120
    0110010            <- 50
    -------
    
    1011010            <- 90
    When you Xor the bits of 120 and 50, you get a value of 90.

  4. #4

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316
    GOTCHA! Thats makes perfect sense now. Thanks.
    SCUZ

Posting Permissions

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



Click Here to Expand Forum to Full Width