Skip to main content

2-bit equality comparator

Short answer

Two 2-bit numbers A1A0 and B1B0 are equal if both bit pairs match. Use XNOR gates: E1 = A1 ⊙ B1, E0 = A0 ⊙ B0, then AND their outputs: x = E1·E0. x=1 only when A = B.

Design a circuit that compares two 2-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 2-bit numbers A=A1A0A = A_1A_0 and B=B1B0B = B_1B_0 are equal only when each pair of corresponding bits is equal. Bit equality is given by the XNOR gate.

Truth table (16 rows; x = 1 only when A = B)

A1A0A_1A_0B1B0B_1B_0x
00001
01011
10101
11111
any other pair0

So

x=A1′A0′B1′B0′+A1′A0B1′B0+A1A0′B1B0′+A1A0B1B0x = A_1'A_0'B_1'B_0' + A_1'A_0B_1'B_0 + A_1A_0'B_1B_0' + A_1A_0B_1B_0

Simplification

Group the terms by the bit-1 pair and the bit-0 pair:

x=(A1′B1′+A1B1)(A0′B0′+A0B0)=(A1⊙B1)(A0⊙B0)=(A1⊕B1)‾⋅(A0⊕B0)‾\begin{aligned} x &= (A_1'B_1' + A_1B_1)(A_0'B_0' + A_0B_0) \\ &= (A_1 \odot B_1)(A_0 \odot B_0) \\ &= \overline{(A_1 \oplus B_1)}\cdot\overline{(A_0 \oplus B_0)} \end{aligned}

The K-map (rows A1A0A_1A_0, columns B1B0B_1B_0) has 1s only on the diagonal cells 0, 5, 10, 15, which cannot be grouped, confirming that the SOP form has four terms; the XNOR form is the simplest circuit.

Logic circuit

 A1 --+
      +--[XNOR]-- E1 --+
 B1 --+                |
                       +--[AND]--- x
 A0 --+                |
      +--[XNOR]-- E0 --+
 B0 --+

Alternative: x=(A1⊕B1)+(A0⊕B0)‾x = \overline{(A_1 \oplus B_1) + (A_0 \oplus B_0)}, i.e. two XOR gates followed by one NOR gate.

Check: A=10A = 10, B=10B = 10: E1=1E_1 = 1, E0=1E_0 = 1, so x=1x = 1. A=10A = 10, B=11B = 11: E0=0E_0 = 0, so x=0x = 0.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Digital Logic chapter 4 questions →