Here is a neat trick to swap two variables without using a third one. I’ve learned it from Patrick Greussay when I was studying AI. If memory serves me well, he discovered it while reviewing some satellite management code at MIT. I’ve seen it again later in some IBM code. It is using the beauty of the xor logic operator, and works on any same length bit fields, regardless of how you re-interpret them. In addition to a basic example, I am also illustrating the method using a union with floats to demonstrate this. Used with vector registers and SIMDs, it can be very handy. In particular, if you throw in some masking bit-ops, you can preserve any bit field from being swapped. So, next time memory is sparse or too far, why don’t you a = a ^ b; b = b ^ a; a = a ^ b;