Assume a, b, c are CPU registers, x, y, z are constants, and C syntax.
a = x /* some number */
b = y /* some other number */
c = z /* some third number */
a ^= b
/* a == x^y */
b ^= c
/* b == y^z */
c ^= a
/* c == z^x^y */
a ^= c
/* a == z^x^y^x^y == z^x^x^y^y == z */
b ^= c
/* b == y^z^z^x^y == x */
c ^= a
/* c == z^x^y^z == y^x
c ^= b
/* c == y^x^x == y */
and now a, b, c contain the original values of c, a, b respectively, only the three variables a, b, c have changed, and no temporary expressions were evaluated (all modification was in-place). |