Saturday, 28 September 2013

XOR operation in C++

XOR operation in C++

How does the XOR logical operator works on more than two values?
For instance, in an operation such as 1 ^ 3 ^ 7 ?
0 0 0 1 // 1
0 0 1 1 // 3
0 1 1 1 // 7
__
0 1 0 1 // 5
yields for some reason 0 1 0 1, where as it should have, as I thought
yield: 0 1 0 0, since XOR is only true when strictly one of the operands
is true.

No comments:

Post a Comment