a = a + b; b = a - b; a = a - b;

“Macha the dal in the microwave is done. The palak in the bowl on the table seems thawed enough, most of the ice has melted. Take a third bowl, put the dal in it, put the palak in the microwave bowl, and set it for 3 min.”

“Cha, if we could XOR swap the dal and palak we wouldn't need a third bowl da.”

As Charles ‘Peanuts’ Schulz said, "Happiness is a warm Nai." (and a hungry Nikhil and TS).
--

The title is the poor man’s swap program. It interchanges the values of ‘a’ and ‘b’ without using a third variable. The XOR swap does exactly the same thing, but the incisively analytical reader would of course prefer the XOR swap because it sounds cooler :-)

:-)
blog comments powered by Disqus

Blogger Templates by Blog Forum