Skip to main content
1 of 2
kenny
  • 22.5k
  • 8
  • 52
  • 88

@VonC has it right, it's a neat mathematical trick. Imagine 4 bit words and see if this helps.

word1 ^= word2;
word2 ^= word1;
word1 ^= word2;


word1    word2
0101     1111
after 1st xor
1010     1111
after 2nd xor
1010     0101
after 3rd xor
1111     0101
Kenny
  • 22.5k
  • 8
  • 52
  • 88