Thursday, September 10, 2009

Exchange variables for experts - or these who want to be

To show how cool you could code, you can use the following snippet to impress your girlfriend 8)

estimating x and y are integers
x = x ^ y;
y = y ^ x;
x = x ^ y;

shorter
x ^= y;
y ^= x;
x ^= y;

and a one liner if you like sunglasses
x ^=  y; y ^=  x; x ^=  y;

Cool as ice ...

No comments:

Post a Comment