Skip to main content

4-bit equality comparator

Short answer

Compare each bit pair with an XNOR gate: xi = Ai ⊙ Bi. AND all four outputs: X = x3·x2·x1·x0. X=1 iff A=B. Alternatively, XOR each pair and NOR the results: X = ̅(A3⊕B3)+...+(A0⊕B0).

Design a circuit that compares two 4-bit numbers, A and B, to check if they are equal. The circuit has one output X, so that X = 1 if A = B and X = 0 if A ≠ B.

Two 4-bit numbers A=A3A2A1A0A = A_3A_2A_1A_0 and B=B3B2B1B0B = B_3B_2B_1B_0 are equal only when every pair of corresponding bits is equal. Equality of one pair is detected by an XNOR gate.

Bit-equality signals

xi=Ai⊙Bi=AiBi+Ai′Bi′,i=0,1,2,3x_i = A_i \odot B_i = A_iB_i + A_i'B_i', \quad i = 0, 1, 2, 3
AiA_iBiB_ixix_i
001
010
100
111

Output

X=1X = 1 only if all four xi=1x_i = 1:

X=x3x2x1x0=(A3⊙B3)(A2⊙B2)(A1⊙B1)(A0⊙B0)X = x_3x_2x_1x_0 = (A_3 \odot B_3)(A_2 \odot B_2)(A_1 \odot B_1)(A_0 \odot B_0)

Equivalent form with XOR and NOR:

X=(A3⊕B3)+(A2⊕B2)+(A1⊕B1)+(A0⊕B0)‾X = \overline{(A_3 \oplus B_3) + (A_2 \oplus B_2) + (A_1 \oplus B_1) + (A_0 \oplus B_0)}

A full truth table would have 28=2562^8 = 256 rows with X=1X = 1 in only 16 of them (A=BA = B), so the bit-wise method is used instead of a K-map.

Logic circuit

 A3 --+
 B3 --+--[XNOR]-- x3 --+
 A2 --+                |
 B2 --+--[XNOR]-- x2 --+
                       +--[AND 4]--- X
 A1 --+                |
 B1 --+--[XNOR]-- x1 --+
 A0 --+                |
 B0 --+--[XNOR]-- x0 --+

Gates: four 2-input XNOR gates and one 4-input AND gate.

Examples

ABx3x2x1x0x_3x_2x_1x_0X
1011101111111
1011100111010
0110111001110

This is the "A = B" part of the 7485 4-bit magnitude comparator.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Digital Logic chapter 4 questions →