Have you ever wondered how computers and calculators—both of which are nothing more than mindless boxes of plastic, wires, and other strange parts—manage to add numbers? And so quickly! Math Dude has the second part of the story.
Exclusive OR (aka, XOR)
Indeed, there are several other logic gates that are built by combining two or more primitive AND, OR, and NOT gates. Of particular importance for today is a gate called “exclusive OR”—aka, XOR. An XOR gate does exactly what it sounds like. By which I mean that while a regular OR gate gives TRUE when either or both inputs are TRUE, an exclusive OR gate gives TRUE exclusively when one or the other—but not both—inputs are TRUE. In the world of 1s (meaning TRUE) and 0s (meaning FALSE), this means that 0 XOR 0 = 0, 1 XOR 0 = 1, 0 XOR 1 = 1, and (this is the biggie) 1 XOR 1 = 0.
Why is this XOR logic gate useful? To understand that we need to think back to how binary addition works. In particular, let’s think about all the things that can happen when we add two bits—namely, we can have: 0 + 0 = 0, 1 + 0 = 1, 0 + 1 = 1, or 1 + 1 = 10. If you compare the first three results with the first three XOR operations we talked about earlier, you’ll see that they are identical.
And what about the last XOR operation—1 XOR 1 = 0? How does it compare to the last binary addition problem, 1 + 1 = 10? It turns out that the 0 from the XOR is what’s called the “sum bit” (which is just the digit on the right) of the binary addition problem. The 1 from the 10 in 1 + 1 = 10 is what’s called the “carry bit” (exactly analogous to the carry digit in normal decimal addition). The big take-away from this is that the XOR operation gives us the sum bit in binary addition. Which means that we’ve found the first half of the solution we’ve been working towards! And it also means that an XOR logic gate is the first big piece of our adding machine.