XOR and XNOR gates
Compare two inputs and detect whether their values match.
For two inputs, XOR detects different values and XNOR detects matching values. These operations are useful in comparisons and binary addition.
XOR gate
XOR outputs 1 when exactly one of its two inputs is 1.
Turn on one switch, then the other. Notice that the output returns to 0 when both inputs are on.
Click an input to change its value.
| A | B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
XNOR gate
XNOR outputs 1 when both inputs have the same value. Its output is the inverse of XOR.
The editor includes an XNOR component. This example builds the same function from XOR followed by NOT.
Click an input to change its value.
| A | B | Output |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Use XOR in addition
XOR calculates the sum bit when adding two one-bit inputs. An AND gate calculates the carry bit.
See Build a half adder for the combined circuit.