XOR has a few useful properties:
x^0=x
x^x=0
x^y=y^x
Commutative- Pairs within a sequence can be removed:
x^y^x=y
Given this, you can swap a two variables without an intermediary variable:
x = x ^ y
y = x ^ y
x = x ^ y
This can also be used to find a missing or duplicated element within a set.
Assume a âmainâ set of 1-n. Assume a separate âmissingâ set containing all but 1 of the numbers. XOR all of the main set, XOR all of the missing set and then XOR these two values and you have the missing number.