4 ms·
Understanding XOR: it's just a diff
- Matumio 12y agoXOR 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.
- 2510c39011c5 12y agoActually 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 12y agoHacker'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 12y agoI agree. The book itself is very thin; but the content is incredibly rich...