Exclusive OR (XOR)

We know OR — it outputs 1 if A or B is 1. AND — only if both are 1. NOT — the opposite. Now meet XOR: Exclusive OR. It outputs 1 only when exactly one of the inputs is 1. If both are 0 or both are 1, the output is 0.

Think of XOR as a "difference detector." It answers the question: "Are these two bits different?" If yes → 1. If no → 0. This property makes XOR uniquely valuable in digital circuits. An AND gate can't tell you if bits differ; an OR gate fires even when both are the same (both 1). Only XOR distinguishes "same" from "different."

XOR is the cornerstone of binary addition. When adding two bits, the sum bit is A XOR B (it's 1 when they differ, 0 when both are 1 because that produces a carry). The carry bit is A AND B. Together, these two gates form a half-adder — the simplest arithmetic circuit possible.

Practical example. XOR has a fascinating property: if you XOR a value twice with the same key, you get the original value back. A XOR B XOR B = A. This is the basis of XOR encryption, used everywhere from simple ciphers to RAID-5 disk arrays (where parity blocks are computed with XOR). It's also how graphics hardware does fast cursor rendering — XOR the cursor shape onto the screen, and XOR it again to erase it, leaving the original pixels perfectly restored.