A B --- A XOR B 0 0 ----- 0 0 1 ----- 1 1 0 ----- 1 1 1 ----- 0
Another way to express this is that the result is true if they are different or false if they are the same.
Useful PropertyMathematically, XOR is both associative and commutative. What this means is that if
C = A xor B then B = C xor A or B = A xor C
A = B xor C A = C xor B
This can be used to disguise text.
'A' xor 0x5516 = 0x1416
By Xoring this value with 0x5516 again the original value 'A' is recovered.
int c = a^b;