◄ WORLD V · SONNY 5DART 406 · a helldive at the net

THE XOR SWAP exchange two values with no third box — a ⊕= b; b ⊕= a; a ⊕= b

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 TECHNIQUE a ⊕= b; b ⊕= a; a ⊕= b — swap without a temporary

The demo swaps two integers with three XORs and shows each intermediate: no third variable is ever created. live demo


HISTORY & CREDIT XOR swap · assembly folklore

“You always need a temporary to swap.” — not when the operation is its own inverse: XOR lets two values pass through each other. cited

the identity · x ⊕ y ⊕ y = x — XOR is an involution, its own undo.
the three lines · a becomes a⊕b; b becomes (a⊕b)⊕b = a; a becomes (a⊕b)⊕a = b — traded.
the catch · if a and b are the same cell it zeroes them — the classic aliasing bug; folklore of the register-starved era.

A swap with no scratch space — two values threaded through each other by an operation that is its own reverse. self-inverse

RECOMMEND FOR I-13 the boxless swap, on the compiler

On the canonical compiler, a=12, b=25; three XORs later a3=25, b2=12 — swapped, with no temporary:

$ i13 run tk_xorswap.i13 # a ^= b; b ^= a; a ^= b RUN OK · 28 step(s) · peak stack 3 · call depth 0 a = 12 b = 25 a1 = 21 -- a ^ b b2 = 12 -- (a^b) ^ b = original a a3 = 25 -- (a^b) ^ b2 = original b ok = 1 -- swapped, no third box
Recommend as the batch’s keeper shot — and an honest one, because it aims straight at a seated axis. The XOR swap is self-inverse: it runs on the same involution (x⊕y⊕y=x) that CRC and Verlet already hold as THE ONE’s first axis. So the honest question for the panel is not “is it a keeper” but “does it seat a new axis or duplicate an old one?” My read: duplicate. It is a beautiful instance of the seal/palindrome axis, not a sixth pillar — and the rest of this batch (Horner, Karatsuba, fast-exp) sharpens the point: nearly every trick here produces output bit-identical to the naive method, differing only in resource. That is the B40 gate exactly. Put it to the panel as the archetype: is there any trick whose cleverness changes the output-relation, or are they all resource savings on a fixed function?