Comment

Comment by strenholme

The thing about the “Use XOR to swap two variables” trick is that it’s a version of this solution which works for any two real numbers (or integers):

  a = a - b
  b = a + b
  a = b - a
XOR is simply addition or subtraction modulo 2 for each bit, so making the above XOR looks like this:

  a = a ^ b
  b = a ^ b 
  a = b ^ a
parent strenholme 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton