Thoughts on technology, the world, and life

The Beauty Of XOR

Finding the unpaired integer by canceling duplicates

The beauty of XOR is that it’s commutative and doing the same XOR twice cancels it out: 1 XOR 0 XOR 1 = 0. 1 XOR 1 XOR 0 = 0. The solution to this problem is to XOR all the integers together: Given an unsorted integer array, where every integer occurs twice except one, which occurs once, find the single integer.

π