XOR gate
High when its two inputs disagree.
Truth table
| a | b | Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
At a glance
- Boolean expression
- a ⊻ b
- Engineering notation
- a ⊕ b
- Inputs
- Two
- Output is high when
- its two inputs differ
How the XOR gate behaves
An exclusive or gate outputs 1 when exactly one of its two inputs is 1. Put another way, it outputs 1 when the inputs differ and 0 when they are the same, which makes it a one bit difference detector.
XOR is the gate that answers "are these two different?". That single property explains nearly every use it has: comparing values, adding bits, flipping bits on demand and counting parity are all the same question asked in different contexts.
Building it from other gates
Each of these is equivalent to the XOR gate. Paste any of them into the simulator with ctrl+E to see the circuit.
| Construction | Expression | Equals |
|---|---|---|
| Sum of products | (a & !b) | (!a & b) | a ^ b |
| OR without the overlap | (a | b) & !(a & b) | a ^ b |
| From NAND gates only | !(!(a & !(a & b)) & !(b & !(a & b))) | a ^ b |
Reference card
The symbol in both standards and the truth table on one image, for notes or a slide.
Click to download the XOR reference cardWhere the XOR gate is used
- The sum output of a half adder: 1 + 1 gives 0 and carries, which is exactly what XOR does.
- Comparing two values for equality, since a XOR b is 0 only when a and b match.
- A controlled inverter: XOR a signal with 1 to invert it, or with 0 to pass it through unchanged.
- Parity generators and checkers, and the same trick underpins the simplest error detection schemes.
In the simulator
XOR is in the Logic menu, with two inputs. For a wider parity check, chain XOR gates together: the result is 1 when an odd number of inputs are high.
Questions about the XOR gate
What is the difference between OR and XOR?
They only differ on the last row of the truth table. When both inputs are 1, OR outputs 1 and XOR outputs 0. XOR is the "one or the other, but not both" version.
Why is XOR used in adders?
Because adding two bits gives 0 for 0+0, 1 for 0+1 and 1+0, and 0 with a carry for 1+1. That pattern is exactly XOR, and the carry is exactly AND. Together they form the half adder.