To swap two variables you were taught to grab a third: t=a; a=b; b=t. The trick throws the third box away. Three exclusive-ORs in place — a ⊕= b; b ⊕= a; a ⊕= b — and the two values have traded, using no scratch register at all. It works because XOR is its own inverse: x ⊕ y ⊕ y = x, so each line cancels one copy and deposits the other. It is the purest bit-trick — a swap that runs both ways, folding the corpus’s own palindrome law into three instructions.
The demo swaps two integers with three XORs and shows each intermediate: no third variable is ever created. live demo
“You always need a temporary to swap.” — not when the operation is its own inverse: XOR lets two values pass through each other. cited
A swap with no scratch space — two values threaded through each other by an operation that is its own reverse. self-inverse
On the canonical compiler, a=12, b=25; three XORs later a3=25, b2=12 — swapped, with no temporary: