3.7 XNOR Gate: Detecting Equality
Define the XNOR gate as inverted XOR, explain its role as an equality detector, and read its truth table.
The XNOR (exclusive NOR) gate is simply XOR with its output inverted: Y = (A ⊕ B)'. Where XOR fires when its two inputs differ, XNOR fires — outputs 1 — exactly when its two inputs are the same. This single property makes XNOR the natural, direct hardware implementation of an equality check between two bits: rather than computing 'are these different?' and then having to invert the answer in a separate step, XNOR gives you 'are these the same?' in one gate, which is exactly why the spec introduces it as an equality detector.
Core Concept: Inverted XOR — Inputs Must Match
The Boolean expression Y = (A ⊕ B)' reads as 'take the XOR of A and B, then complement the result'. Because XOR itself is 1 exactly when A and B differ and 0 exactly when they match, complementing that flips the rule entirely: XNOR is 1 exactly when A and B match, and 0 exactly when they differ. As with NAND and NOR earlier in this module, XNOR's truth table is the precise bitwise complement of its underlying gate's (XOR's) truth table.
The spec states this equality property directly and concretely: A XNOR B = 1 when both bits are equal. This is the cleanest possible statement of the gate's purpose — it is a one-bit equality comparator, and chaining several XNOR gates (one per bit position, then ANDing all their outputs together) is exactly how a multi-bit equality comparator circuit is built.
• Y = (A ⊕ B)' — XOR followed by inversion. • Output is 1 exactly when A and B match (both 0, or both 1); 0 exactly when they differ. • Truth table is the bitwise complement of XOR's truth table. • Directly usable as a one-bit equality detector: XNOR(A,B) = 1 means 'A equals B'.
Step-by-Step: Deriving XNOR's Truth Table from XOR's
Because XNOR is defined purely as the complement of XOR, its truth table can be derived without any new reasoning, simply by flipping every output value in the XOR truth table already established in Module 3.6. XOR's table is (0,0)→0, (0,1)→1, (1,0)→1, (1,1)→0; complementing every output gives XNOR's table: (0,0)→1, (0,1)→0, (1,0)→0, (1,1)→1 — notice the two matching-input rows (both 0, both 1) now read 1, and the two differing-input rows read 0, exactly matching the 'inputs must match' rule stated above.
This derive-by-complementing approach is a generally useful technique in digital logic: whenever a gate is explicitly defined as 'X, but inverted' (NAND from AND, NOR from OR, XNOR from XOR), you never need to re-derive its truth table from first principles — you can always start from the base gate's table and flip every output column.
• Step 1: Start from XOR's truth table. • Step 2: Complement every output value (0 → 1, 1 → 0). • Step 3: Read off the result: XNOR is 1 on the two matching-input rows, 0 on the two differing-input rows.
Practical and Real-World Application: Equality Comparators and Parity
XNOR gates are the standard building block of digital equality comparators: to compare two multi-bit binary numbers for equality, XNOR each corresponding pair of bits (bit 0 of A with bit 0 of B, bit 1 of A with bit 1 of B, and so on), then AND all of those XNOR outputs together. The final AND output is 1 only if every single bit position matched — which is exactly the condition for the two full numbers being equal. This structure appears directly inside the magnitude comparator circuits covered later in Module 6.8.
XNOR is also used for even-parity checking, the complement use case to XOR's odd-parity generation: because chained XOR gates naturally compute odd parity, chaining an XNOR at the final stage (or equivalently, inverting the final XOR output) flips the check to even parity, letting a receiver verify that an even number of bits changed (or didn't) during transmission, depending on which parity convention a given communication protocol uses.
Common Mistake and the Tricky Concept
A subtle trap with XNOR, mirroring the one flagged for XOR in Module 3.6, is over-extending the two-input 'A equals B' intuition to circuits with more than two inputs without re-deriving the actual logic. For genuinely comparing two multi-bit numbers for equality, you do not chain XNOR gates end-to-end the way you might chain XOR gates for parity; instead, you compute one XNOR per corresponding bit pair and then AND all those individual equality results together, because 'the whole numbers are equal' requires every bit position to match simultaneously, which is exactly what AND (not a chain of XNORs) expresses.
It is also worth being precise about naming: XNOR is sometimes informally called an 'equivalence gate' or 'coincidence gate' in older textbooks, but its underlying Boolean definition is unambiguous and always the same — the complement of XOR, Y = (A ⊕ B)' — regardless of which name a particular source uses for it.
XNOR Gate Notation and Truth Table
XNOR's truth table is the bitwise complement of XOR's truth table. A XNOR B = 1 is read directly as 'A equals B'.
Boolean expression:
Y = (A ⊕ B)'
Truth Table:
A | B | Y
---+---+---
0 | 0 | 1
0 | 1 | 0
1 | 0 | 0
1 | 1 | 1
Symbol: XOR body + output bubbleCode Examples
This is the spec's own framing of XNOR: it directly reports whether two single bits are equal, reading 1 on exactly the two rows where A and B hold the same value and 0 on the two rows where they differ. Expected result: Y = 1 on matching-input rows, Y = 0 on differing-input rows XNOR(A,B) = 1 means A equals B
Comparing two 4-bit numbers for full equality requires an XNOR per bit position plus a final AND of all four XNOR outputs — any single mismatched bit would make its XNOR output 0, which would then zero out the final AND result and correctly flag the numbers as unequal.
Equal = XNOR₃ · XNOR₂ · XNOR₁ · XNOR₀
A XNOR B = 1 when both bits are equal
A=0, B=0 → Y = 1 (equal)
A=0, B=1 → Y = 0 (not equal)
A=1, B=0 → Y = 0 (not equal)
A=1, B=1 → Y = 1 (equal)A = 1011, B = 1011
Bit 3: XNOR(1,1) = 1
Bit 2: XNOR(0,0) = 1
Bit 1: XNOR(1,1) = 1
Bit 0: XNOR(1,1) = 1
Equal = AND(1,1,1,1) = 1 → A and B are equal2-Input XNOR Gate
1 exactly on the two rows where A and B match.
A ══╮
)──o── Y (XOR body + output bubble)
B ══╯
A | B | Y
---+---+---
0 | 0 | 1
0 | 1 | 0
1 | 0 | 0
1 | 1 | 1Important Rules
Y = (A ⊕ B)' — XOR followed by inversion.
Output is 1 exactly when A and B match, 0 exactly when they differ — the equality function.
Derive its truth table by complementing XOR's truth table, output by output.
Multi-bit equality requires one XNOR per bit position ANDed together, not a chain of XNORs.
Equality Comparators and Even-Parity Checking
XNOR gates form the per-bit comparison stage of digital equality comparators (used inside magnitude comparators, Module 6.8) and provide the complementary check to XOR-based odd-parity generation, letting receivers verify even-parity data depending on the communication protocol's convention.
How It's Built From Other Gates
The most direct way to build XNOR: invert an XOR gate's output, Y = (A⊕B)′. In practice, a dedicated CMOS transmission-gate XNOR is often used instead for speed, but the XOR-then-NOT view is the one to reason about first.
Chaining XNOR gates end-to-end across many bits the same way XOR gates are chained for parity, expecting the result to mean 'all bits are equal'.
Compute one XNOR per corresponding bit pair, then AND every XNOR output together — only that AND result correctly represents 'every bit position matched'.
XNOR's 'equal' meaning is inherently a per-pair (two-input) statement; combining several equality checks into one overall equality verdict requires AND (every check must pass), not further chained XNORing, which does not preserve the 'all match' meaning across more than two inputs.
[tricky-problem] According to the spec, what condition makes A XNOR B equal to 1? A. When A and B are both 1 only B. When both bits are equal (either both 0 or both 1) C. When A and B differ D. When at least one of A or B is 1
B. When both bits are equal (either both 0 or both 1) — The spec states directly: 'A XNOR B = 1 when both bits are equal.' This includes both the both-0 case and the both-1 case — XNOR does not distinguish which value they're equal at, only that they match.
[interview] How would you derive the XNOR truth table without re-deriving it from a Boolean expression? A. It cannot be derived from any other gate's table. B. Start from the XOR truth table and complement every output value, since XNOR is defined as (A ⊕ B)'. C. Start from the AND truth table and complement every output value. D. XNOR and NAND always share the same truth table.
B. Start from the XOR truth table and complement every output value, since XNOR is defined as (A ⊕ B)'. — Because XNOR is explicitly defined as the complement of XOR, Y = (A ⊕ B)', its entire truth table can be obtained by flipping every output bit in XOR's truth table — no independent re-derivation is needed, the same technique used to get NAND's table from AND's and NOR's table from OR's.
Design a circuit (in words) that lights an LED only when two 2-bit numbers A1A0 and B1B0 are exactly equal.
Feed (A1,B1) into one XNOR gate and (A0,B0) into a second XNOR gate. AND the two XNOR outputs together and connect the AND output to the LED: the LED lights only when both bit positions match, i.e., only when A1A0 equals B1B0 exactly.
You need one equality check per bit position, then a way to require both checks to hold simultaneously.