The XOR works because every time you XOR a bit with 1 you flip it, and every time you XOR a bit with 0 it stays the same. So the result of XORing all the data save the missing number gives you the 'negative' impression of XORing all the numbers. XORing these two together restores your lost number.