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

# 4-bit equality comparator

Digital Logic · Chapter 4: Data Processing Circuits

- Asked in: 2082 Baisakh, 5 marks
- Video: [Q. 4.21: Design a combinational circuit that compares two 4-bit numbers to check if they are equal.](https://www.youtube.com/watch?v=hQXA73nDVB0) — Dr. Dhiman (Learn the art of problem solving) 
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/digital_logic/equality-comparator-4bit
- Whole chapter: https://www.bctengineer.com/md/semester_3/digital_logic/chapter-4

## Question

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.

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

## Answer

Two 4-bit numbers $A = A_3A_2A_1A_0$ and $B = 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

$$
x_i = A_i \odot B_i = A_iB_i + A_i'B_i', \quad i = 0, 1, 2, 3
$$

| $A_i$ | $B_i$ | $x_i$ |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |

#### Output

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

$$
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 = \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 $2^8 = 256$ rows with $X = 1$ in only 16 of them ($A = B$), so the bit-wise method is used instead of a K-map.

#### Logic circuit

```text
 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

| A | B | $x_3x_2x_1x_0$ | X |
|---|---|---|---|
| 1011 | 1011 | 1111 | 1 |
| 1011 | 1001 | 1101 | 0 |
| 0110 | 1110 | 0111 | 0 |

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

## Check yourself

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

1. Which gate detects that a single pair of bits Ai and Bi are equal?
   A. XOR
   B. NAND
   C. XNOR
   D. OR
   Answer: C. XNOR gives 1 when its two inputs are the same. (Key point: Bit equality gate)

2. How is the final output X formed from the four bit-equality signals?
   A. OR of the four, so X = 1 if any pair matches
   B. XOR of the four
   C. AND of only the two MSB signals
   D. AND of all four, so X = 1 only if every pair matches
   Answer: D. A = B only when all four bit pairs are equal, so X = x3.x2.x1.x0. (Key point: Combining bits)

3. Why does the answer use a bit-wise method instead of a K-map?
   A. The truth table has 256 rows with only 16 having X = 1, which makes a K-map impractical
   B. A K-map cannot represent XNOR
   C. The circuit is sequential
   D. A K-map needs flip-flops
   Answer: A. With 8 inputs, 2^8 = 256 rows, so a bit-wise comparison is much simpler. (Key point: Why not a K-map)

## Close variants set in other exams

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

## 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 magnitude comparator](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Amagnitude-comparator-2bit) — Digital Logic, chapter 4, asked 6×
- [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 other subjects

- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
