Swapping two variables with XOR
Dec 20, 2020
I once got asked in an interview question what the following code does in Python:
a = a^b
b = b^a
a = a^b
I found it weird… It was a multiple choice question and my intuition said that this thing swapped the values of the variables (at least I was not mistaken). So I investigated further and now I explain it in my YouTube channel: