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

# 3-bit magnitude comparator

Digital Logic · Chapter 4: Data Processing Circuits

- Asked in: 2075 Chaitra, 5 marks; 2074 Chaitra, 5 marks (asked 2 times)
- Video: [3-Bit Magnitude Comparator](https://www.youtube.com/watch?v=eAIwJAF1MbQ) — preethi chunduru
- 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-3bit
- Whole chapter: https://www.bctengineer.com/md/semester_3/digital_logic/chapter-4

## Question

Explain the operation of 3 bit magnitude comparator with truth table and draw the circuit.

## Short answer

Comparison starts at MSB. Equality of bit pairs gives xi = Ai XNOR Bi. (A=B) = x2·x1·x0. (A>B) = A2·B2' + x2·A1·B1' + x2·x1·A0·B0'. (A<B) is the dual: A2'·B2 + x2·A1'·B1 + x2·x1·A0'·B0.

## Answer

A **magnitude comparator** compares two binary numbers and indicates whether $A>B$, $A=B$ or $A<B$. A 3-bit comparator compares $A = A_2A_1A_0$ with $B = B_2B_1B_0$ (6 inputs, 64 combinations, 3 outputs).

#### Operation

Comparison starts at the most significant bit:

1. If $A_2 \ne B_2$, the result is decided: $A_2 = 1, B_2 = 0$ gives $A>B$; $A_2 = 0, B_2 = 1$ gives $A<B$.
2. If $A_2 = B_2$, compare $A_1$ and $B_1$ in the same way.
3. If $A_2 = B_2$ and $A_1 = B_1$, compare $A_0$ and $B_0$.
4. If all three pairs are equal, $A = B$.

Bit equality is detected by X-NOR gates:
$$
x_i = A_iB_i + \overline{A_i}\,\overline{B_i}, \quad i = 0, 1, 2
$$

#### Truth table (condensed)

The full table has 64 rows; it is written compactly by bit priority (X = any value):

| $A_2$ vs $B_2$ | $A_1$ vs $B_1$ | $A_0$ vs $B_0$ | $A>B$ | $A=B$ | $A<B$ |
|---|---|---|---|---|---|
| $A_2>B_2$ (1,0) | X | X | 1 | 0 | 0 |
| $A_2<B_2$ (0,1) | X | X | 0 | 0 | 1 |
| $A_2=B_2$ | $A_1>B_1$ | X | 1 | 0 | 0 |
| $A_2=B_2$ | $A_1<B_1$ | X | 0 | 0 | 1 |
| $A_2=B_2$ | $A_1=B_1$ | $A_0>B_0$ | 1 | 0 | 0 |
| $A_2=B_2$ | $A_1=B_1$ | $A_0<B_0$ | 0 | 0 | 1 |
| $A_2=B_2$ | $A_1=B_1$ | $A_0=B_0$ | 0 | 1 | 0 |

Sample rows: $A=101, B=011$ gives $A>B$ (decided at $A_2$); $A=110, B=111$ gives $A<B$ (decided at $A_0$); $A=B=010$ gives $A=B$.

#### Output expressions

$$
\begin{aligned} (A=B) &= x_2x_1x_0 \\ (A>B) &= A_2\overline{B_2} + x_2A_1\overline{B_1} + x_2x_1A_0\overline{B_0} \\ (A<B) &= \overline{A_2}B_2 + x_2\overline{A_1}B_1 + x_2x_1\overline{A_0}B_0 \end{aligned}
$$

#### Circuit

```text
A2,B2 ─[XNOR]─ x2     A1,B1 ─[XNOR]─ x1
A0,B0 ─[XNOR]─ x0

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

A2, B2' ─────────[AND]──┐
x2, A1, B1' ─────[AND]──┼─[OR]──────── A>B
x2, x1, A0, B0' ─[AND]──┘

A2', B2 ─────────[AND]──┐
x2, A1', B1 ─────[AND]──┼─[OR]──────── A<B
x2, x1, A0', B0 ─[AND]──┘
```

Gates: 3 X-NOR, 7 AND, 2 OR (plus inverters for the complemented bits). The $A<B$ output can also be obtained as $\overline{(A>B) + (A=B)}$ using one NOR gate.

## Check yourself

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

1. How does a 3-bit comparator decide the result?
   A. It compares LSBs first
   B. It compares from the MSB downward, moving to the next bit only when the bits are equal
   C. It adds A and B
   D. It compares all bits independently and ORs them
   Answer: B. The first unequal bit pair from the MSB decides A > B or A < B. (Key point: Comparison method)

2. Which is the A > B expression?
   A. A2B2' + x2A1B1' + x2x1A0B0'
   B. A2B2' + A1B1' + A0B0'
   C. x2x1x0
   D. A2'B2 + x2A1'B1 + x2x1A0'B0
   Answer: A. Each lower bit pair counts only if all higher bit pairs are equal (x terms). (Key point: A>B expression)

3. What gives A = B?
   A. x2 + x1 + x0
   B. x2·x1·x0
   C. A2B2 + A1B1 + A0B0
   D. x2 ⊕ x0
   Answer: B. All three bit pairs must be equal, so the three X-NOR outputs are ANDed. (Key point: Equality output)

4. A = 110 and B = 111. Which output is 1?
   A. A > B
   B. A = B
   C. A < B
   D. None
   Answer: C. The first two bits are equal; at A0 = 0, B0 = 1, so A < B. (Key point: Example)

## Close variants set in other exams

- [2-bit magnitude comparator](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Amagnitude-comparator-2bit) — 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
- [Circuit giving 2's complement of a 4-bit number](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Atwos-complement-generator) — 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
