Digital Comparator: Working, Types, 1-Bit to n-Bit Comparators, Truth Tables, Logic Circuits & Applications

What is a Digital Comparator?

A digital comparator, also called a magnitude comparator, is a hardware device that compares two binary numbers and determines whether one number is greater than, less than, or equal to the other.

An XNOR gate acts as the simplest comparator because its output becomes “1” only when both input bits are equal. A voltage comparator is the analog equivalent of a digital comparator. Many microcontrollers include analog comparators that can be read or used to trigger interrupts.

Digital comparators operate using logic gates based on Boolean algebra. They compare two binary inputs—A and B—and determine whether:

Digital comparators are classified into two major types:

Types of Digital Comparators

1. Identity Comparator

An identity comparator checks only whether two inputs are equal. It has two inputs and one output.

For two inputs P and Q:

2. Magnitude Comparator

A magnitude comparator compares the complete magnitude of two binary numbers and produces outputs for:

1-Bit Magnitude Comparator

A 1-bit comparator compares two single-bit inputs. It has two inputs (A and B) and three outputs indicating whether A > B, A = B, or A < B.

Truth Table for 1-Bit Comparator

A B A < B A = B A > B
0 0 0 1 0
0 1 1 0 0
1 0 0 0 1
1 1 0 1 0

Boolean Expressions

2-Bit Magnitude Comparator

A 2-bit comparator compares two 2-bit numbers. There are 16 possible input combinations. Based on the comparison, the outputs indicate P > Q, P = Q, or P < Q.

If both inputs are the same, the equality output becomes HIGH. If P’s binary value is greater than Q’s, the P > Q output is HIGH, and vice-versa.

n-Bit Magnitude Comparator

For higher-bit comparisons (4-bit, 8-bit, etc.), creating truth tables becomes impractical. Instead, general mathematical expressions help determine how many combinations correspond to each output.

Total Possible Combinations

For two n-bit inputs:

Total combinations = 22n

Equal Output (P = Q)

Two n-bit numbers are equal when all bits match.

P = Q occurs 2n times.

Not Equal Output (P ≠ Q)

P ≠ Q occurs 22n − 2n times.

Greater Than / Less Than

Since the total non-equal cases are split evenly:

Example (3-bit Inputs)

Applications of Digital Comparators