XOR Properties
a ^ a = 0, a ^ 0 = a, commutative and associative. Pairs cancel.
XOR Tricks: Swap without a temporary
b = a xor b = 15 xor 9 = 6. That is the original a: (6 xor 9) xor 9 leaves 6, because the 9 cancels itself.
Cost
- Space
- O(1)
Before this
Leads to
Topics that need this one first.
Taught by the same lesson
XOR Tricks covers these too, in the same run.