Swap two variables using XOR
Most people would swap two variables x and y using a temporary variable, like this:
tmp = x
x = y
y = tmp
Here’s a neat programming trick to swap two values without needing a temp:
x = x xor y
y = x xor y
x = x xor y
Crowd Favorites
Math & Numbers
- Mental math shortcuts, adding 1-100
- Understanding exponents and the natural log
- Div, Curl, Flux, Gradient and other Vector Calculus topics
Programming & Web Development
- Site speedups with HTTP caching, gzip compression
- Understanding Rails, Web debugging, and Javascrtipt
- Swap bytes with XOR, byte order, unicode
