---
title: "2-bit magnitude comparator"
subject: "Digital Logic"
chapter: 4
key: "semester_3/digital_logic:magnitude-comparator-2bit"
source: https://www.bctengineer.com/q/semester_3/digital_logic/magnitude-comparator-2bit
site: BCT Engineering
---

# 2-bit magnitude comparator

Digital Logic · Chapter 4: Data Processing Circuits

- Asked in: 2081 Bhadra, 5 marks; 2070 Chaitra, 5 marks; 2069 Chaitra, 4 marks; 2068 Baisakh, 6 marks (asked 4 times)
- Video: [2-Bit Comparator](https://www.youtube.com/watch?v=BhUUmbz76P0) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/digital_logic/magnitude-comparator-2bit
- Whole chapter: https://www.bctengineer.com/md/semester_3/digital_logic/chapter-4

## Question

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

## 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.

## Answer

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

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

#### Operation

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

Equality of bit $i$ is given by an X-NOR gate:
$$
x_i = A_iB_i + \overline{A_i}\,\overline{B_i} = \overline{A_i \oplus B_i}
$$

#### Truth table

| $A_1A_0$ | $B_1B_0$ | $A>B$ | $A=B$ | $A<B$ |
|---|---|---|---|---|
| 0 0 | 0 0 | 0 | 1 | 0 |
| 0 0 | 0 1 | 0 | 0 | 1 |
| 0 0 | 1 0 | 0 | 0 | 1 |
| 0 0 | 1 1 | 0 | 0 | 1 |
| 0 1 | 0 0 | 1 | 0 | 0 |
| 0 1 | 0 1 | 0 | 1 | 0 |
| 0 1 | 1 0 | 0 | 0 | 1 |
| 0 1 | 1 1 | 0 | 0 | 1 |
| 1 0 | 0 0 | 1 | 0 | 0 |
| 1 0 | 0 1 | 1 | 0 | 0 |
| 1 0 | 1 0 | 0 | 1 | 0 |
| 1 0 | 1 1 | 0 | 0 | 1 |
| 1 1 | 0 0 | 1 | 0 | 0 |
| 1 1 | 0 1 | 1 | 0 | 0 |
| 1 1 | 1 0 | 1 | 0 | 0 |
| 1 1 | 1 1 | 0 | 1 | 0 |

#### Output expressions

$$
\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 = A_1\overline{B_1} + A_0\overline{B_1}\,\overline{B_0} + A_1A_0\overline{B_0}$.)

#### Circuit diagram

```text
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 $x_1$, $x_0$; one AND for $A=B$; two ANDs and an OR for each of $A>B$ and $A<B$ (inverters give the complemented bits).

**Example:** $A = 10$, $B = 11$: $A_1 = B_1$ so $x_1 = 1$; $\overline{A_0}B_0 = 1$, so $A<B = 1$, and the other outputs are 0.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. In a 2-bit comparator, when are A0 and B0 compared?
   A. Always first, since they are the LSBs
   B. Only when A1 = B1
   C. Only when A1 ≠ B1
   D. Only when A0 = 1
   Answer: B. Comparison starts from the MSB; the LSBs matter only if the MSBs are equal. (Key point: Comparison order)

2. Which gate gives the equality x_i of bits A_i and B_i?
   A. XOR
   B. AND
   C. X-NOR
   D. NAND
   Answer: C. x_i = A_iB_i + A_i'B_i' = (A_i ⊕ B_i)', an X-NOR. (Key point: Bit equality)

3. Which expression gives A > B for a 2-bit comparator?
   A. A1B1' + x1A0B0'
   B. A1'B1 + x1A0'B0
   C. A1B1' + x0A0B0'
   D. x1x0
   Answer: A. A > B if A1 > B1, or if A1 = B1 (x1) and A0 > B0. (Key point: A>B expression)

4. A = 10 and B = 11. Which output is 1?
   A. A > B
   B. A = B
   C. A < B
   D. All three
   Answer: C. A1 = B1, then A0'B0 = 1, so A < B; exactly one output is 1. (Key point: Equal output)

## Close variants set in other exams

- [3-bit magnitude comparator](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Amagnitude-comparator-3bit) — Digital Logic, chapter 4, asked 6×

## Related in Digital Logic

- [Hazards in asynchronous design; 2-bit comparator](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Ahazards-2bit-comparator) — Digital Logic, chapter 4
- [2-bit equality comparator](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aequality-comparator-2bit) — Digital Logic, chapter 4, asked 2×
- [4-bit equality comparator](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aequality-comparator-4bit) — Digital Logic, chapter 4, asked 2×
- [Shift register and 4-bit PISO operation](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Ashift-register-piso) — Digital Logic, chapter 7
- [Two 4-bit parallel adder](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aparallel-adder-4bit) — Digital Logic, chapter 5
- [n-bit full adder block diagram](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3An-bit-full-adder) — Digital Logic, chapter 5

## Related in other subjects

- [JK flip-flop operation and truth table](https://www.bctengineer.com/question.md?key=semester_2%2Fbasic_electronics_engineering%3Ajk-flip-flop) — Basic Electronics Engineering, chapter 6
- [Block diagram of a two-stage RC circuit](https://www.bctengineer.com/question.md?key=semester_3%2Fcontrol_systems%3Abd-rc-two-stage) — Control Systems, chapter 2
- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [Wien bridge oscillator circuit and operation](https://www.bctengineer.com/question.md?key=semester_2%2Fbasic_electronics_engineering%3Awien-bridge-draw-explain) — Basic Electronics Engineering, chapter 4, asked 4×
