Many people have heard of how to swap two values without using temporary storage, using XORs. This is often summarised as:
a ^= b ^= a ^= b;
There are other operators that can be used to do the swap, but in the degenerate case, this essentially becomes the XOR trick again.
Filed under: bit-twiddling, embedded
|