
- Digital Electronics - Home
- Digital Electronics Basics
- Types of Digital Systems
- Types of Signals
- Logic Levels And Pulse Waveforms
- Digital System Components
- Digital Logic Operations
- Digital Systems Advantages
- Number Systems
- Number Systems
- Binary Numbers Representation
- Binary Arithmetic
- Signed Binary Arithmetic
- Octal Arithmetic
- Hexadecimal Arithmetic
- Complement Arithmetic
- Base Conversions
- Base Conversions
- Binary to Decimal Conversion
- Decimal to Binary Conversion
- Binary to Octal Conversion
- Octal to Binary Conversion
- Octal to Decimal Conversion
- Decimal to Octal Conversion
- Hexadecimal to Binary Conversion
- Binary to Hexadecimal Conversion
- Hexadecimal to Decimal Conversion
- Decimal to Hexadecimal Conversion
- Octal to Hexadecimal Conversion
- Hexadecimal to Octal Conversion
- Binary Codes
- Binary Codes
- 8421 BCD Code
- Excess-3 Code
- Gray Code
- ASCII Codes
- EBCDIC Code
- Code Conversion
- Error Detection & Correction Codes
- Logic Gates
- Logic Gates
- AND Gate
- OR Gate
- NOT Gate
- Universal Gates
- XOR Gate
- XNOR Gate
- CMOS Logic Gate
- OR Gate Using Diode Resistor Logic
- AND Gate vs OR Gate
- Two Level Logic Realization
- Threshold Logic
- Boolean Algebra
- Boolean Algebra
- Laws of Boolean Algebra
- Boolean Functions
- DeMorgan's Theorem
- SOP and POS Form
- POS to Standard POS Form
- Minimization Techniques
- K-Map Minimization
- Three Variable K-Map
- Four Variable K-Map
- Five Variable K-Map
- Six Variable K-Map
- Don't Care Condition
- Quine-McCluskey Method
- Min Terms and Max Terms
- Canonical and Standard Form
- Max Term Representation
- Simplification using Boolean Algebra
- Combinational Logic Circuits
- Digital Combinational Circuits
- Digital Arithmetic Circuits
- Multiplexers
- Multiplexer Design Procedure
- Mux Universal Gate
- 2-Variable Function Using 4:1 Mux
- 3-Variable Function Using 8:1 Mux
- Demultiplexers
- Mux vs Demux
- Parity Bit Generator and Checker
- Comparators
- Encoders
- Keyboard Encoders
- Priority Encoders
- Decoders
- Arithmetic Logic Unit
- 7-Segment LED Display
- Code Converters
- Code Converters
- Binary to Decimal Converter
- Decimal to BCD Converter
- BCD to Decimal Converter
- Binary to Gray Code Converter
- Gray Code to Binary Converter
- BCD to Excess-3 Converter
- Excess-3 to BCD Converter
- Adders
- Half Adders
- Full Adders
- Serial Adders
- Parallel Adders
- Full Adder using Half Adder
- Half Adder vs Full Adder
- Full Adder with NAND Gates
- Half Adder with NAND Gates
- Binary Adder-Subtractor
- Subtractors
- Half Subtractors
- Full Subtractors
- Parallel Subtractors
- Full Subtractor using 2 Half Subtractors
- Half Subtractor using NAND Gates
- Sequential Logic Circuits
- Digital Sequential Circuits
- Clock Signal and Triggering
- Latches
- Shift Registers
- Shift Register Applications
- Binary Registers
- Bidirectional Shift Register
- Counters
- Binary Counters
- Non-binary Counter
- Design of Synchronous Counter
- Synchronous vs Asynchronous Counter
- Finite State Machines
- Algorithmic State Machines
- Flip Flops
- Flip-Flops
- Conversion of Flip-Flops
- D Flip-Flops
- JK Flip-Flops
- T Flip-Flops
- SR Flip-Flops
- Clocked SR Flip-Flop
- Unclocked SR Flip-Flop
- Clocked JK Flip-Flop
- JK to T Flip-Flop
- SR to JK Flip-Flop
- Triggering Methods:Flip-Flop
- Edge-Triggered Flip-Flop
- Master-Slave JK Flip-Flop
- Race-around Condition
- A/D and D/A Converters
- Analog-to-Digital Converter
- Digital-to-Analog Converter
- DAC and ADC ICs
- Realization of Logic Gates
- NOT Gate from NAND Gate
- OR Gate from NAND Gate
- AND Gate from NAND Gate
- NOR Gate from NAND Gate
- XOR Gate from NAND Gate
- XNOR Gate from NAND Gate
- NOT Gate from NOR Gate
- OR Gate from NOR Gate
- AND Gate from NOR Gate
- NAND Gate from NOR Gate
- XOR Gate from NOR Gate
- XNOR Gate from NOR Gate
- NAND/NOR Gate using CMOS
- Full Subtractor using NAND Gate
- AND Gate Using 2:1 MUX
- OR Gate Using 2:1 MUX
- NOT Gate Using 2:1 MUX
- Memory Devices
- Memory Devices
- RAM and ROM
- Cache Memory Design
- Programmable Logic Devices
- Programmable Logic Devices
- Programmable Logic Array
- Programmable Array Logic
- Field Programmable Gate Arrays
- Digital Electronics Families
- Digital Electronics Families
- CPU Architecture
- CPU Architecture
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.
In this chapter, we will learn about the basics, types, and applications of comparators in digital electronics. So, lets start with the basic definition of a comparator.
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 A2 = 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.
Types of Comparators
Depending on the number of bits, the following are some main types of comparators used in digital circuits −
- 1-Bit Magnitude Comparator
- 2-Bit Magnitude Comparator
- 4-Bit Magnitude Comparator
Let us discuss each type of comparator in detail.
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.
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,
$$\mathrm{E \: = \: \overline{A} \: \cdot \: \overline{B} \: + \: A \: \cdot \: B \: = \: A \: \odot \: B}$$
If A = 0 and B = 1, then A < B. This indicates that the binary number A is less than the binary number B. Therefore,
$$\mathrm{L \: = \: \overline{A} \: B}$$
If A = 1 and B = 0, then A > B. It indicates that the binary number A is greater than the binary number B. Therefore,
$$\mathrm{G \: = \: A \: \overline{B}}$$
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.
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.
$$\mathrm{L \: = \: \overline{A} \: B}$$
$$\mathrm{E \: = \: \overline{A} \: \cdot \: \overline{B} \: + \: A \: \cdot \: B \: = \: A \: \odot \: B}$$
$$\mathrm{G \: = \: A \: \overline{B}}$$
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.
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
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,
$$\mathrm{E \: = \: (A_{0} \: \odot \: B_{0}) \: (A_{1} \: \odot \: B_{1})}$$
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 −
$$\mathrm{L \: = \: \overline{A_{1}} \: B_{1} \: + \: (A_{1} \: \odot \: B_{1}) \: \overline{A_{0}} \: B_{0}}$$
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,
$$\mathrm{G \: = \: A_{1} \: \overline{B_{1}} \: + \: (A_{1} \: \odot \: B_{1}) \: A_{0} \: \overline{B_{0}}}$$
The following figure shows the logic circuit diagram of the 2-bit magnitude comparator −

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,
$$\mathrm{E \: = \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: (A_{1} \: \odot \: B_{1}) \: (A_{0} \: \odot \: B_{0})}$$
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.
From these statements, we can derive the Boolean expression for the output L, which is given below.
$$\mathrm{L \: = \: \overline{A_{3}} \: B_{3} \: + \: (A_{3} \: \odot \: B_{3}) \: \overline{A_{2}} \: B_{2} \: + \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: \overline{A_{1}} \: B_{1} \: + \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: (A_{1} \: \odot \: B_{1}) \: \overline{A_{0}} \: B_{0}}$$
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,
$$\mathrm{G \: = \: A_{3} \: \overline{B_{3}} \: + \: (A_{3} \: \odot \: B_{3}) \: A_{2} \: \overline{B_{2}} \: + \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: A_{1} \: \overline{B_{1}} \: + \: (A_{3} \: \odot \: B_{3}) \: (A_{2} \: \odot \: B_{2}) \: (A_{1} \: \odot \: B_{1}) \: A_{0} \: \overline{B_{0}}}$$
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.
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.
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 −
- Comparators are used to detect changes in voltage levels in electronic circuits.
- Comparators are also used temperature monitoring systems.
- Comparators are used as zero-crossing detector in various power circuits like phase control circuits, motor and power control circuits, etc.
- Comparators are key components in analog to digital converters (ADCs).
- In signal conditioning circuits, the comparators are used for amplification and filtering of signals before processing.
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.