|
-
Oct 2nd, 2000, 04:45 PM
#1
Thread Starter
Hyperactive Member
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.
-
Oct 2nd, 2000, 04:52 PM
#2
Hyperactive Member
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]
-
Oct 2nd, 2000, 04:52 PM
#3
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.
-
Oct 2nd, 2000, 04:55 PM
#4
Thread Starter
Hyperactive Member
GOTCHA! Thats makes perfect sense now. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|