News for hackers. Stuff that matters.
Re:How to Swap two numbers without temp variable in Java by jheriko on Monday February 25, 2013 @10:39AM (#5279406)
two things i'd want to add. firstly the arithmetic with +/- fails when over/underflow occurs. secondly xor works because it is its own inverse. the more generic answer is using any operator that forms a group over the potential values to be swapped... as another comment explains

i remember feeling fantastically clever when i rediscovered this about 15 years ago. it has been of nearly zero value to me since.

Re:How to Swap two numbers without temp variable in Java by imd on Tuesday February 26, 2013 @02:55PM (#5288062)
+/- doesn't fail in a language where + is addition modulo n.
Re:How to Swap two numbers without temp variable in Java by jheriko on Wednesday March 06, 2013 @08:16AM (#5330986)
true, but lots of things work in special cases.
Re:How to Swap two numbers without temp variable in Java by jheriko on Monday February 25, 2013 @10:40AM (#5279415)
oh... and as alluded to but not explained thorougly 'static single assignment' form completely negates the utility of this hack.