Skip to main content

2-bit magnitude comparator

Short answer

A 2-bit magnitude comparator compares A=A1A0 and B=B1B0. Outputs: A>B, A=B, A<B. Equality of each bit pair is given by XNOR: xi = AiBi + Ai'Bi'. A=B = x1 x0; A>B = A1 B1' + x1 A0 B0'; A<B = A1' B1 + x1 A0' B0. Only one output is active. Circuit uses XNORs, ANDs, and ORs.

Explain the operation of two bit magnitude comparator with truth table and circuit diagram.

A magnitude comparator is a combinational circuit that compares two binary numbers A and B and gives three outputs: A>BA>B, A=BA=B and A<BA<B. Exactly one output is 1 at a time.

A 2-bit comparator compares A=A1A0A = A_1A_0 with B=B1B0B = B_1B_0 (4 inputs, 3 outputs).

Operation

  1. Compare the most significant bits first. If A1=1A_1 = 1 and B1=0B_1 = 0, then A>BA>B; if A1=0A_1 = 0 and B1=1B_1 = 1, then A<BA<B.
  2. Only if A1=B1A_1 = B_1 are the LSBs A0A_0, B0B_0 compared in the same way.
  3. A=BA=B only when both bit pairs are equal.

Equality of bit ii is given by an X-NOR gate:

xi=AiBi+Ai‾ Bi‾=Ai⊕Bi‾x_i = A_iB_i + \overline{A_i}\,\overline{B_i} = \overline{A_i \oplus B_i}

Truth table

A1A0A_1A_0B1B0B_1B_0A>BA>BA=BA=BA<BA<B
0 00 0010
0 00 1001
0 01 0001
0 01 1001
0 10 0100
0 10 1010
0 11 0001
0 11 1001
1 00 0100
1 00 1100
1 01 0010
1 01 1001
1 10 0100
1 10 1100
1 11 0100
1 11 1010

Output expressions

(A=B)=x1x0(A>B)=A1B1‾+x1A0B0‾(A<B)=A1‾B1+x1A0‾B0\begin{aligned} (A=B) &= x_1x_0 \\ (A>B) &= A_1\overline{B_1} + x_1A_0\overline{B_0} \\ (A<B) &= \overline{A_1}B_1 + x_1\overline{A_0}B_0 \end{aligned}

(The same results come from 4-variable K-maps of the table, e.g. A>B=A1B1‾+A0B1‾ B0‾+A1A0B0‾A>B = A_1\overline{B_1} + A_0\overline{B_1}\,\overline{B_0} + A_1A_0\overline{B_0}.)

Circuit diagram

A1,B1 ─[XNOR]── x1        A0,B0 ─[XNOR]── x0

x1, x0 ───────────[AND]────────────── A=B

A1, B1' ──────────[AND]──┐
                         ├─[OR]────── A>B
x1, A0, B0' ──────[AND]──┘

A1', B1 ──────────[AND]──┐
                         ├─[OR]────── A<B
x1, A0', B0 ──────[AND]──┘

Gates: 2 X-NOR gates for x1x_1, x0x_0; one AND for A=BA=B; two ANDs and an OR for each of A>BA>B and A<BA<B (inverters give the complemented bits).

Example: A=10A = 10, B=11B = 11: A1=B1A_1 = B_1 so x1=1x_1 = 1; A0‾B0=1\overline{A_0}B_0 = 1, so A<B=1A<B = 1, and the other outputs are 0.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Digital Logic chapter 4 questions →