3 ms·
two things i'd want to add. firstly the arithmetic with +/- fails when over/underflow occurs. secondly xor works because it is its own inverse. the more generic
by jheriko 14y ago
two things i'd want to add. firstly the arithmetic with +/- fails when over/underflow occurs. secondly xor works because it is its own inverse. the more generic answer is using any operator that forms a group over the potential values to be swapped... as another comment explains
i remember feeling fantastically clever when i rediscovered this about 15 years ago. it has been of nearly zero value to me since.