The XOR gate (exclusive OR)
The XOR gate (exclusive OR) gives 1 when its two inputs are different, and 0 when they are the same. It is “one or the other, but not both”. Think of a staircase light with a switch at the top and one at the bottom: flipping either switch changes the light.
Formula Y = A ⊕ B
Truth table
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Try it Click the inputs to change them.
Y0
Where it is used
XOR is the gate of binary addition: adding two bits gives a sum bit of A XOR B (see the half adder). It also compares bits, finds errors with parity bits, and is used in encryption, because XOR-ing a message twice with the same key gives the message back.
Build it yourself
Four NAND gates make an XOR gate. Try it in the XOR from NAND challenge.