Rosetta Code talk:Village Pump/CS Pages Wanted

From Rosetta Code

Swapping in a ring

XOR swap is limited to the modulus of 2n. A more general swap is based on addition and subtraction, or equivalently on addition and negative inverse in the ring. This one works for any modulus. Here is an example in Ada. Given <lang ada> type N is mod 5; -- Ring of 0,1,2,3,4 X, Y : N; </lang> Swap X and Y: <lang ada> X := X + Y; Y := X - Y; X := X - Y; </lang> 5 is not a power of two, yet it still works. --Dmitry-kazakov 09:14, 17 March 2009 (UTC)

Isn't the reason that the XOR swap works because integers are stored as binary and XOR will do a bitwise operation? I think the XOR one is better because not all languages have modulus types, but pretty much all languages (if not all) represent integers in binary (or can at least do bitwise operations on them as if they were binary). Maybe I'm missing the problem. --Mwn3d 18:54, 17 March 2009 (UTC)