Join Nostr
2025-08-13 15:16:56 UTC

Nicolai Hähnle on Nostr: The trick for swapping two values without extra storage and without a dedicated swap ...

The trick for swapping two values without extra storage and without a dedicated swap instruction by three XORs is reasonably well known.

If you want to rotate N values, you can just do this as a sequence of swaps which under these constraints means 3(N-1) XORs.

Is there a cheaper sequence of XORs? If so, what's the asymptotic bound?