The XOR gate
The XOR gate (eXclusive OR) outputs 1 when its two inputs are different: one is 0, the other 1. If they are equal (00 or 11), it outputs 0. In other words, it is a difference detector.
In real life
The two-way switch in a hallway: two switches control the same lamp, and flipping either one changes the lamp's state. That is exactly an XOR. In a processor, XOR works out the sum of two bits (without the carry): it is the basis of addition. It can also scramble a message: an XOR with a key, then the same XOR again to decrypt.
The truth table
| A | B | S |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The symbol
The classic symbol is the OR symbol with a second arc on the inputs. The European symbol is a rectangle with =1 inside (“exactly one input set to 1”, which is only true for two inputs: cascaded XORs on three or more inputs output 1 for an odd number of 1s). The 74HC86 integrated circuit contains four XOR gates.
Your turn to play
Place the right gate and flip the inputs: when every row of the table is green, the lamp lights up.
Your turn: 4 questions
Answer and see straight away whether you were right. You need 3 right answers out of 4 to pass the page. Your score stays on this device, nothing is sent.
Frequently asked questions
What is the difference between XOR and OR?
OR also outputs 1 when both inputs are 1. XOR does not: it outputs 1 only if exactly one input is 1.
What is the XOR gate used for?
To compare two bits (are they different?), to add bits, and to encrypt data with a key.
How do you make an XOR from AND, OR and NOT gates?
A XOR B = (A AND NOT B) OR (NOT A AND B). You need two NOT gates, two AND gates and one OR gate.
What about a three-input XOR?
XOR gates in cascade output 1 when the number of inputs set to 1 is odd. It is a parity detector, not “exactly one input set to 1”.
The other gates: The AND gate · The OR gate · The NOT gate · The NAND and NOR gates · The truth table · All the pages