xor definition (this sentence is to make the title acceptable) [duplicate]
Possible Duplicate:
What does ‘^’ do in c# (Enums)?
This may be a noobish question but...nowhere have I seen what Xor means in C++ or C#. I think it might mean and/or and if it does, I'm smart cause that's a blind guess =D. I use C# now but I'm pretty sure xor means the same thing. The problem is - I don't know what xor means. I know that xor is represented by a ^ though. I also would like to know what ^^ means.
Exclusive or between two bits means that the result is 1 if one and only one bit is 1.
The truth table is:
| 0 | 1
---+---+---
0 | 0 | 1
1 | 1 | 0
When you talk about xoring a larger value, it's just taking each bit one at a time, so:
1111 0000
xor 1010 1010
---- ----
= 0101 1010
For what it's worth, a full list of binary operations:
and
, 1 only if both its inputs are 1, else 0.or
, 0 only if both its inputs are 0, else 1.xor
, 1 only if one (not both) of its inputs is 1, else 0.not
, 1 only if its input is 0, else 1.
And the truth tables:
and| 0 | 1 or| 0 | 1 xor| 0 | 1 not| 0 | 1
---+---+--- ---+---+--- ---+---+--- ---+---+---
0 | 0 | 0 0 | 0 | 1 0 | 0 | 1 | 1 | 0
1 | 0 | 1 1 | 1 | 1 1 | 1 | 0
A google search for "define: xor" will point you to http://en.wikipedia.org/wiki/Xor, the fountain of all knowledge. Reading this will give you an insight as to what exclusive-or (XOR) means :)
Goodluck
[edit] And just to clarify, xor does not mean and/or, sorry. And the definition of xor is programming language independent.
XOR stands for 'eXclusive OR'. Exclusive Or operation result is true, only if one of the arguments is true, not both.
Having 1 as the value of true, and 0 as the value of false, bitwise operation gives 1 when only one of the bits at corresponding position is 1.
精彩评论