DIGITAL ELECTRONICS - COMPARATORS
In digital electronics, a comparator is a combinational logic circuit that is used to
compare the magnitudes of two binary numbers. Comparators are used in several
different electronic circuits like analog to digital converters, voltage level detectors,
zero-crossing detectors, etc.
The most basic example of a comparator is an XNOR gate which produces a high or
logic 1 output only when both its inputs are equal.
A. What is a Comparator?
A digital combinational circuit used to compare the magnitude of two binary numbers
to determine the equality or non-equality is called a comparator.
Therefore, the main function of a comparator is to compare the values of input numbers
and produce an output indicating whether the numbers are equal or specifies which of
the numbers is greater.
Let us understand the working of a comparator with the help of an example.
Consider two 3-bit binary numbers A2A1A0 and B2B1B0. These two binary numbers are
said to be equal if all their corresponding bits coincide. In other words, these two binary
numbers are equal if A 2 = B2, A1 = B1, and A0 = B0.
The block diagram of a typical comparator is shown in the following figure −
Here, A and B are the input bits, and L, E, and G are the output lines, where L indicates
which number is smaller, E indicates equality, and G indicates the greater number.
B. Types of Comparators
Depending on the number of bits, the following are some main types of comparators
used in digital circuits −
i. 1-Bit Magnitude Comparator
ii. 2-Bit Magnitude Comparator
1
iii. 4-Bit Magnitude Comparator
1-Bit Magnitude Comparator
A 1-bit magnitude comparator is a logic circuit which can compare two binary
numbers of one bit each. It produces an output that indicates the relationship between
the two input numbers.
In other words, a 1-bit magnitude comparator is one that compares two 1-bit binary
numbers and generates an output showing whether one number is equal to or greater
than or less than the other.
The block diagram of a 1-bit magnitude comparator is shown in the following figure −
Here, A and B are the 1-bit input numbers, and L, E, and G are the output lines indicating
less than or equal to or greater than relationship between A and B respectively.
Let us understand the working this type of comparator.
i. If A = 0 and B = 0 or if A = 1 and B = 1, then A = B. It indicates that the two
binary numbers are equal. Therefore,
E=A’⋅B’ + A⋅B=A⊙B
ii. If A = 0 and B = 1, then A < B. This indicates that the binary number A is less
than the binary number B. Therefore,
L=A’B
iii. If A = 1 and B = 0, then A > B. It indicates that the binary number A is greater
than the binary number B. Therefore,
G=AB’
The 1-bit magnitude comparator compares the corresponding bits of the input numbers
A and B. For this, it uses different types of logic gates.
2
The truth table of the 1-bit magnitude comparators is given below −
Inputs Outputs
A B L (A < B) E (A = B) G (A > B)
0 0 0 1 0
0 1 1 0 0
1 0 0 0 1
1 1 0 1 0
We can use this truth table to obtain the Boolean expression of the 1-bit magnitude
comparator.
L=A’B
E=A’⋅B’+A⋅B=A⊙B
G=AB’
The logic circuit diagram of the 1-bit magnitude comparator is shown in the following
figure.
It consists of two AND gates, two NOT gate, and an XNOR gate.
2-Bit Magnitude Comparator
A digital combinational circuit used to compare the magnitudes of two 2-bit binary
numbers and determine the relationship between them is called a 2-bit magnitude
comparator.
3
Hence, the 2-bit magnitude comparator compares the values represented by two 2-bit
binary numbers and then generates an output that indicates whether one number is equal
to or greater than or less than the other.
The block diagram of a typical 2-bit magnitude comparator is shown in the following
figure −
Here, the lines A0A1 and B0B1 represents two 2-bit binary number inputs and the lines
L, E, and G represents the less than, equal to, and greater than output lines.
We can understand the operation of the 2-bit magnitude comparator with the help of its
truth table given below −
Inputs Outputs
A1 A0 B1 B0 L (A < B) E (A = B) G (A > B)
0 0 0 0 0 1 0
0 0 0 1 1 0 0
0 0 1 0 1 0 0
0 0 1 1 1 0 0
0 1 0 0 0 0 1
0 1 0 1 0 1 0
0 1 1 0 1 0 0
0 1 1 1 1 0 0
1 0 0 0 0 0 1
1 0 0 1 0 0 1
1 0 1 0 0 1 0
1 0 1 1 1 0 0
1 1 0 0 0 0 1
1 1 0 1 0 0 1
1 1 1 0 0 0 1
1 1 1 1 0 1 0
Let us now derive the Boolean expression for the outputs L, E, and G.
Case 1: A = B
4
The comparator produces an output A = B which is E, if A0 = B0 and A1 = B1.
Therefore, the Boolean expression for the output E will be,
E=(A0⊙B0)(A1⊙B1)
Case 2: A < B
The comparator produces an output A < B which is L, if
• A1 = 0 and B1 = 1, OR
• A1 = B1 and A0 = 0 and B0 = 1.
From these statements, we can write the Boolean expression for the output L as follows
L=A1’B1+(A1⊙B1)A0’B0
Case 3: A > B
The output of the comparator will be A > B i.e., G, if
• A1 = 1 and B1 = 0, OR
• A1 = B1 and A0 = 1 and B0 = 0.
From these statements, the Boolean expression for the output G will be,
G=A1B1’ + (A1⊙B1)A0B0
The following figure shows the logic circuit diagram of the 2-bit magnitude comparator
5
4-Bit Magnitude Comparator
The 4-bit magnitude comparator is used in more complex digital circuits like
microprocessors, microcontrollers, and many more.
It is a type of comparator that can compare the values or magnitudes of two 4-bit binary
numbers and produce an output indicating whether one number is equal to or less than
or greater than the other.
The block diagram of the 4-bit magnitude comparator is shown in the following figure
−
Let us now understand the working of this 4-bit magnitude comparator. For that
consider A = A3A2A1A0 is the first 4-bit binary number and B = B3B2B1B0 is the second
4-bit binary number.
The comparator will show the results as follows −
Case 1: A = B
The comparator will produce an output A = B which is E, if all the corresponding bits
in the two numbers are equal i.e., A3 = B3 and A2 = B2 and A1 = B1 and A0 = B0.
In this case, the Boolean expression of the output will be,
E=(A3⊙B3)(A2⊙B2)(A1⊙B1)(A0⊙B0)
Case 2: A < B
The comparator will produce an output A < B which is L, if
• A3 = 0 and B3 = 1, OR
• A3 = B3 and if A2 = 0 and B2 = 1, OR
• A3 = B3 and if A2 = B2 and if A1 = 0 and B1 = 1, OR
• A3 = B3 and if A2 = B2 and if A1 = B1 and if A0 = 0 and B0 = 1.
6
From these statements, we can derive the Boolean expression for the output L, which is
given below.
L=A3’B3+(A3⊙B3)A2’B2+(A3⊙B3)(A2⊙B2)A1’B1+(A3⊙B3)(A2⊙B2)(A1⊙B1)A0’B0
Case 3: A > B
The comparator produces an output A > B which is G, if
• A3 = 1 and B3 = 0, OR
• A3 = B3 and if A2 = 1 and B2 = 0, OR
• A3 = B3 and if A2 = B2 and if A1 = 1 and B1 = 0, OR
• A3 = B3 and if A2 = B2 and if A1 = B1 and if A0 = 1 and B0 = 0.
Hence, from these statements, we can write the Boolean expression for the output G
which is,
G=A3B3’+(A3⊙B3)A2B2’+(A3⊙B3)(A2⊙B2)A1B1’+(A3⊙B3)(A2⊙B2)(A1⊙B1)A0B0’
The logic circuit implementation of the 4-bit magnitude comparator is shown in the
following figure −
Comparator IC
A comparator IC is an integrated circuit which is designed to compare two binary
numbers and produce an output based on the comparison results.
7
A commonly used comparator IC is IC 7485 which is a 4-bit magnitude comparator IC.
It is widely in digital electronic applications to compare two 4-bit binary numbers.
The IC 7485 compares corresponding bits of the two input numbers and determines
whether one number is equal to or greater than or less than the other. The pin diagram
of the IC 7485 is depicted in the following figure.
This IC is widely used in various digital circuits such as microprocessors,
microcontrollers, control systems, and arithmetic logic units.
C. Applications of Comparators
The comparators are fundamental components in various digital circuits. They provide
capabilities to compare voltage levels and make decisions.
Some of the key applications of comparators in the field of digital electronics are listed
below −
i. Comparators are used to detect changes in voltage levels in electronic circuits.
ii. Comparators are also used temperature monitoring systems.
iii. Comparators are used as zero-crossing detector in various power circuits like
phase control circuits, motor and power control circuits, etc.
iv. Comparators are key components in analog to digital converters (ADCs).
v. In signal conditioning circuits, the comparators are used for amplification and
filtering of signals before processing.
8
Conclusion
In conclusion, a comparator is a combinational logic circuit used in various digital
electronic applications to compare two similar quantities like two 2-bit binary numbers
or two voltage levels, etc.
Comparators help us to make decisions based on a comparison of two input values.
They are widely used in several different electronic devices and systems such as
arithmetic logic units, microprocessor-based systems, control systems, automation
systems, and telecommunication systems.
Depending on the number of input bits required for a particular application, we can
design a 1-bit, 2-bit, or 4-bit comparator. Also, comparators are available in the form of
integrated circuit. The most commonly used IC comparator is IC 7485 which is a 4-bit
magnitude comparator.