Lurker News

Comments (491) 209 threads

Show all comments

Showing thread 123 of 209

keithnz1 reply#
Xor Swap.... https://en.wikipedia.org/wiki/XOR_swap_algorithm

not because it's super practical ( and there are other variations using other operators )
I like it because it is super simple and when I first encountered it early on in my learning, it was really not immediately obvious why it worked. It's probably been the simplest piece of code that's surprised me.

make31 reply#
I was asked this in an interview. I was a bit pissed
QML#
Doesn't sound too bad; a basic property of XOR is that two of them cancel out, so y ⊕ x ⊕ x is just y.