Comparator Tutorial
Comparator Tutorial
Comparator
1. Comparator
1. Equality or identity comparator
2. Magnitude comparator
3. A 4-bit magnitude comparator
4. Cascading comparator
5. Applications of comparators
2. Summary
Learning Objectives
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
1. Comparator
Comparator is a combinational logic circuit that compares the magnitudes of two binary
quantities to determine which one has the greater magnitude. In other word, a comparator
determines the relationship of two binary quantities.
quantities An exclusive OR gate can be used as a
basic comparator.
Digital comparators are also called as binary or logic comparators. Comparator is a very
useful combinational circuit capable of comparing two numbers as input in binary form and
determines whether one number is greater than, less than or equal to other number. This logic
circuit is used for testing whether the binary number at one input is greater than or less than
or equal to another binary number.
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
3
Equality comparator requires two input binary numbers A and B for comparison as shown in
fig. 3. There is only one output indicating whether the input numbers are equal or not.
Output of the comparator is at logic ‘1’ if the two input words A and B match otherwise the
output remains at logic ‘0’. Out of the 2n combinations, there is only one input combination that
is correct and other combinations will result in inequality.
inequality
This comparator can be used for simple circuits like electronic lock and security systems where
binary password consisting of n bits compared with another preset code. Let us discuss the
implementation of simple 1-bit equality comparator.
comparator
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
4
Let us study 1-bit equality comparator using simple XOR circuit. The truth table of XOR
indicates the operation of Identity or Equality comparator. When both the inputs of the
comparator are equal then the output is active LOW indicating matching of the input code, other
wise output is at logic ‘1’ indicating the mismatch.
mismatch
Let us study ACTIVE HIGH 1-bit equality comparator using simple XNOR circuit as shown in
fig. 5. The truth table of XNOR indicates the operation of Identity or Equality comparator. If
two inputs are identical then the output of comparator is ‘1’ else provides ‘0’ indicating
mismatch in the input code.
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
5
A1 A0 B1 BO A=B
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 0 1 1 0
0 1 0 0 0
0 1 0 1 1
0 1 1 0 0
Fig. 6: 2-bit Equality comparator
0 1 1 1 0
1 0 0 0 0
In two bit equality comparator as shown in fig.6,
fig two bit binary
1 0 0 1 0
numbers A and B represented as A1A0 and B11B0 are compared.
1 0 1 0 1
Here A1 and B1 are the most significant bits, and A0 and B0 are
1 0 1 1 0
the least significant bits of numbers A and B respectively.
respectively A1 is
1 1 0 0 0
compared with B1 and A0 is compared the B0.. If A1 is equal to
1 1 0 1 0
B1 and A0 is equal to B0 output of a two bit comparator will be
1 1 1 0 0
HIGH. If A1 is not equal to B1 or A0 is not equal to B0 output
1 1 1 1 1
will be LOW as shown in the table.
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
6
Magnitude comparator as the name suggest compares only the magnitude of the two binary
numbers and not the sign. It can also be used to indicate the equality of the input numbers. In
addition, the magnitude comparators has two additional outputs to indicate whether input A is
greater that input B and whether input A is less than input B as shown in fig.7.
Inputs Outputs
A B A>B A=B A<B
0 0 0 1 0
0 1 0 0 1
1 0 1 0 0
1 1 0 1 0
In 1-bit magnitude Comparator, A, B are two 1 bit number and there are three outputs
corresponding to A>B, A=B and A<B respectively as shown in fig. 8 . The Boolean
expressions for 1-bit magnitude comparator are
C AB
DAB
E AB
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
7
For implementation of this comparator, XNOR gate, AND gates and inverters are also used. It is
very easy to derive the Boolean expressions from the truth table by visual inspection.
A 2-bit comparator compares two binary numbers, each of two bits and produces their relation
such as one number is equal or greater than or less than the other. The figure below shows the
block diagram of a two-bit comparator which has four inputs and three outputs.
Inputs Outputs
A1 A0 B1 BO A>B A=B A<B
0 0 0 0 0 1 0
0 0 0 1 0 0 1
0 0 1 0 0 0 1
0 0 1 1 0 0 1
Figure 9: 2-bit magnitude comparator 0 1 0 0 1 0 0
0 1 0 1 0 1 0
The fig. 9 shows the block diagram of a two--
0 1 1 0 0 0 1
bit comparator which has four inputs and three
0 1 1 1 0 0 1
outputs.
1 0 0 0 1 0 0
The first number A is designated as A = A1A00 1 0 0 1 1 0 0
and the second number is designated as B = 1 0 1 0 0 1 0
B1B0. This comparator produces three outputs 1 0 1 1 0 0 1
as (A>B), (if A = B) and (A<B). 1 1 0 0 1 0 0
1 1 0 1 1 0 0
Let us prepare the K-map for each output so as
1 1 1 0 1 0 0
to implement the 2-bit magnitude comparator.
1 1 1 1 0 1 0
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
11
The K-map and Boolean expression for the outputs A>B, A=B and A>B of comparator are
shown in fig. 10.
A1’A0’ 1
A1’A0 1
A1A0 1
A1A0’ 1
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
9
By using above obtained Boolean equation for each output, the logic diagram can be
implemented by using four NOT gates, seven AND gates, two OR gates and two Ex-NOR gates.
Figure 11 shows the logic diagram of a 2-bit comparator using basic logic gates. It is also
possible to construct this comparator by cascading of two 1-bit comparators.
Magnitude comparator can be used to compare two four-bit words. The two 4-bit numbers are A
= A3 A2 A1 A0 and B= B3 B2 B1 B0 where A3 and B3 are the most significant bits. It
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
10
compares each of these bits in one number with bits in that of other number and produces one of
the following outputs as A = B, A < B and A>B.
A>B The output function table of 4-bit magnitude
comparator is shown in Figure 13.
INPUT OUTPUTS
A3 B3 A2 B2 A1 B1 A0 B0 A>B A=B A<B
A3 >B3 X X X 1 0 0
A3 <B3 X X X 0 0 1
A3 =B3 A2>B2 X X 1 0 0
A3 =B3 A2<B2 X X 0 0 1
A3 =B3 A2=B2 A1>B1 X 1 0 0
A3 =B3 A2=B2 A1<B1 X 0 0 1
The circuit for comparing two n -bit numbers has 22n entries in the truth table and becomes too
cumbersome, even with n = 3. On the other hand, as one may suspect, a comparator circuit
possesses a certain amount of regularity.
Digital functions that possess an inherent well-defined
well regularity can usually be designed by
means of an algorithm—a procedure which specifies a finite set of steps
Electronic Science
Algorithm (equality)
The algorithm is a direct application of the procedure a person uses to compare the relative magnitudes of
two numbers. Consider two numbers, A and B , with four digits each.
Each subscripted letter represents one of the digits in the number. The two numbers are equal if all pairs
of significant digits are equal: A3 = B3, A2 = B2, A11 = B1, and A0 = B0. When the numbers are binary,
the digits are either 1 or 0, and the equality of each pair of bits can be expressed logically with an
exclusive-NOR function as
xi = AiBi + Ai’Bi’ for i = 0, 1, 2, 3
where xi = 1 only if the pair of bits in position i are equal (i.e., if both are 1 or both are 0).
A<B
A=B
A>B
The equality of the two numbers A and B is displayed in a combinational circuit by an output
binary variable that we designate by the symbol (A = B) . This binary variable is equal to 1 if the
input numbers, A and B , are equal, and is equal to 0 otherwise.
For equality to exist, all xi variables must be equal to 1, a condition that dictates an AND
operation of all variables:
(A = B) = X3X2X1X0
The binary variable (A = B) is equal to 1 only if all pairs of digits of the two numbers are equal.
Algorithm (inequality)
To determine whether A is greater or less than B , we inspect the relative magnitudes of pairs of
significant digits, starting from the most significant position. If the two digits of a pair are equal,
we compare the next lower significant pair of digits.
digits The comparison continues until a pair of
unequal digits is reached. If the corresponding digit of A is 1 and that of B is 0, we conclude that
A > B. If the corresponding digit of A is 0 and that of B is 1, we have A < B. The sequential
comparison can be expressed logically by the two Boolean functions
A > B = A3B3’ + x3 A 2B2’ + x3x2A1B11’ + x3x2x1A0B0’
A < B = A3’B3 + x3A2’B2 + x3x2A1’B1 + x3x2x1A0’B0
The symbols (A > B) and(1A < B) are binary output variables that are equal to 1 when A > B
and A < B, respectively.
11
IC 7485
ICs are available in TTL as well as CMOS logic family ICs and some of these ICs include
IC 7485 (4-bit comparator), IC 4585 (4-bit comparator in CMOS family) and IC 74AS885
(8-bit comparator). Fig. 14 indicates an IC for 4-bit magnitude comparator. The 74LS85
compares two unsigned 4-bit binary numbers , the unsigned numbers are A3, A2, A1, A0
and B3, B2, B1, B0.
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator
Function Table of 7485 4-Bit Comparator
Comparators are used in control applications in which the binary numbers representing physical
variables such as temperature, position, etc. are compared with a reference value. Then the
outputs from the comparator are used to drive the actuators so as to make the physical variables
closest to the set or reference value. In addition, comparators are also used in following
applications.
2. Compare two binary words in microprocessors, computers for interfacing the external
devices.
Summary
Combinational circuits are the logic circuits in which the outputs at any instant of time depend on
the inputs present at that instant only. In Combinational circuit, for n input variables, there are 2n
possible combinations of binary input values. There are 3 types of combinational circuits: Data
processing, Data transfer and code converters.
The design of combinational circuits begins with problem definition and ends with a logic circuit or set of
Boolean expressions. In many applications, logic diagram is available but correlation between
input and output is not known. The analysis of combinational circuits is the reverse process of
design.
Comparator is a combinational logic circuit that compares the magnitudes of two binary
quantities to determine which one has the greater magnitude. An exclusiveOR gate can be used
as a basic comparator. There are two types of comparators:
comparators Equality or Identity Comparator and
Magnitude or inequality comparator.
Cascading inputs provide a means for expanding the comparison operation to more than four bits
by cascading two or more 4-bit comparators.
Digital Electronics
Electronic Science
9. Combinational circuits & Comparator