XNOR Gate
The XNOR gate outputs 1 when its inputs are equal; it is the complement of XOR and acts as an equality detector.
What it does
XNOR, exclusive-NOR, is the complement of XOR. Its output is 1 when the inputs are the same and 0 when they differ. It is often called an equality or coincidence gate.
Truth table
| A | B | A XNOR B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Algebraic form
XNOR equals NOT(A XOR B), which expands to A AND B, OR NOT A AND NOT B. It is commutative and associative, and satisfies A XNOR 1 = A and A XNOR 0 = NOT A.
Equality across many bits
To test whether two multi-bit words are equal, XNOR each pair of bits and AND all the results. A single mismatch drops the AND to 0, so the final signal is 1 only for exact equality. This is the heart of a magnitude comparator's equality path.
In code
out = 1 - (a ^ b) # XNOR of two 0/1 bits
equal = all(x == y for x, y in zip(word1, word2))
Where it appears
- Bit and word comparators.
- Parity checking where even parity is the target.
- Coincidence detectors in control and timing logic.
- Building blocks in error-correcting and matching circuits.
As the natural companion to XOR, XNOR provides the sameness test that pairs with XOR's difference test.