Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Understanding XOR: it's just a diff (biesnecker.com)
6 points by biesnecker on Oct 6, 2014 | hide | past | favorite | 4 comments


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

* Hacker's Delight, http://goo.gl/llQumw


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.


I agree.

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


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: