145 words
1 minutes
The XOR Operator
XOR is a logical operator that returns 1
if two bits are different and 0
if they are the same. Here is the truth table:
x | y | x ^ y |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Some good links to explore:
Some Useful properties
XOR and 0: x ^ 0 = x
When one of the two arguments to XOR is 0, the result is the other argument. This can be seen from the truth table above by observing at the rows where y = 0
, which are the first and third rows.
XOR on the same argument: x ^ x = 0
When both arguments to XOR are the same, the result is always 0. This can be confirmed by inspecting the truth table again, specifically the rows where x = y
, which are the first and last rows. Intuitively, this means that applying XOR to the same arguments cancels them out.
The XOR Operator
https://rabisiddique.com/posts/xor-operator/Author
Rabi Siddique
Published at
2023-10-15