

Understanding XOR: it's just a diff - biesnecker
http://biesnecker.com/2014/10/06/swapping-variables-with-xor/

======
2510c39011c5
Actually bit addition in ALU is usually implemented using an XOR gate (with an
AND gate to compute carry)...But as "diff" is essentially addition (over
complement numbers), they mean the same thing...

Also note that XOR is associative -- that's the key to prove the XOR
swapping...

For those who are interested in binary tricks, there are several good
resources:

* HAKMEM, [http://goo.gl/F6sBjt](http://goo.gl/F6sBjt)

* Hacker's Delight, [http://goo.gl/llQumw](http://goo.gl/llQumw)

~~~
thomasmarcelis
Hacker's Delight is one of the most fun tech books I have read. It is filled
with fun tricks and algorithms, with each of them adequately explained.

~~~
2510c39011c5
I agree.

The book itself is very thin; but the content is incredibly rich...

------
Matumio
XOR is fascinating. It can be understood as binary addition, discarding the
carry (the higher bit of the result). It is also useful for drawing a cursor
pixmap: XOR the screen with the cursor, XOR again to remove the cursor,
without ever copying the area below the cursor.

