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

# 2-bit equality comparator

Digital Logic · Chapter 4: Data Processing Circuits

- Asked in: 2078 Bhadra, 5 marks
- 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/equality-comparator-2bit
- Whole chapter: https://www.bctengineer.com/md/semester_3/digital_logic/chapter-4

## Question

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.

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

## Answer

Two 2-bit numbers $A = A_1A_0$ and $B = 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)

| $A_1A_0$ | $B_1B_0$ | x |
|---|---|---|
| 00 | 00 | 1 |
| 01 | 01 | 1 |
| 10 | 10 | 1 |
| 11 | 11 | 1 |
| any other pair | | 0 |

So

$$
x = 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:

$$
\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 $A_1A_0$, columns $B_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

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

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

**Check:** $A = 10$, $B = 10$: $E_1 = 1$, $E_0 = 1$, so $x = 1$. $A = 10$, $B = 11$: $E_0 = 0$, so $x = 0$.

## Check yourself

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

1. When are two 2-bit numbers A1A0 and B1B0 equal?
   A. When A1 = B0 and A0 = B1
   B. When each pair of corresponding bits is equal
   C. When A1 + A0 = B1 + B0 in any arrangement
   D. When only the MSBs are equal
   Answer: B. Equality needs A1 = B1 and A0 = B0. (Key point: Equality condition)

2. Which gate outputs 1 when two bits are equal?
   A. XOR
   B. NAND
   C. XNOR
   D. NOR
   Answer: C. XNOR gives 1 when its two inputs are the same. (Key point: Bit equality gate)

3. What is the simplest expression for x?
   A. (A1 XOR B1)(A0 XOR B0)
   B. (A1 XNOR B1) + (A0 XNOR B0)
   C. (A1 XNOR B1)(A0 XNOR B0)
   D. A1B1 + A0B0
   Answer: C. x = (A1 ⊙ B1)(A0 ⊙ B0): two XNOR gates feeding an AND gate. (Key point: Final expression)

4. Why does the K-map not help to simplify the SOP form?
   A. The 1s lie on the diagonal and cannot be grouped
   B. All cells are 1
   C. It has only one 1
   D. The don't-cares fill the map
   Answer: A. The 1s are at cells 0, 5, 10, 15, none adjacent, so the XNOR form is the simplest. (Key point: K-map observation)

## Close variants set in other exams

- [4-bit equality comparator](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aequality-comparator-4bit) — 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
