comparator_encoder
comparator_encoder
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.
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.
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
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.
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 −
What is Encoder?
• An Encoder is a combinational circuit that performs the reverse operation of
a Decoder.
• It has a maximum of 2^n input lines and ‘n’ output lines, hence it encodes the
information from 2^n inputs into an n-bit code.
• It will produce a binary code equivalent to the input, which is active High. Therefore,
the encoder encodes 2^n input lines with ‘n’ bits.
The basic principle of an encoder is to assign a unique binary code to each possible input.
For example, a 2-to-4 line encoder has 2 input lines and 4 output lines and assigns a unique 4-
bit binary code to each of the 2^2 = 4 possible input combinations.
The output of an encoder is usually active low, meaning that only one output is active (low) at
any given time, and the remaining outputs are inactive (high).
The active low output is selected based on the binary code assigned to the active input.
There are different types of encoders, including priority encoders, which assign a priority to
each input, and binary-weighted encoders, which use a binary weighting system to assign
binary codes to inputs.
In summary, an encoder is a digital circuit that converts a set of binary inputs into a unique
binary code that represents the position of the input. Encoders are widely used in digital
systems to convert parallel inputs into serial codes.
Types of Encoders
There are different types of Encoders which are mentioned below.
• Octal to Binary Encoder (8 to 3 Encoder)
• Decimal to BCD Encoder
• Priority Encoder
4 to 2 Encoder
• The 4 to 2 Encoder consists of four inputs Y3, Y2, Y1 & Y0, and two outputs A1
& A0. At any time, only one of these 4 inputs can be ‘1’ in order to get the respective
binary code at the output. The figure below shows the logic symbol of the 4 to 2
encoder.
What is a Decoder?
• In digital electronics, a combinational logic circuit that converts an N-bit binary input
code into M output channels in such a way that only one output channel is activated for
each one of the possible combinations of inputs is known as a decoder.
• In other words, a combinational logic circuit which converts N input lines into a
maximum of 2N output lines is called a decoder.
• Therefore, a decoder is a combination logic circuit that is capable of identifying or
detecting a particular code. The operation that a decoder performs is referred to as
decoding. A general block diagram of a decoder is shown in Figure-1.
Here, the decoder has N input lines and M (2N) output lines. In a decoder, each of the N input
lines can be a 0 or a 1, hence the number of possible input combinations or codes be equal to
2N. For each of these input combinations, only one of the M output lines will be active, and
all other output lines will remain inactive.
Types of Decoders
There are several types of decoders present. But, based on the input and output lines present,
decoders may be classified into the following three types −
• 2 to 4 Decoder
• 3 to 8 Decoder
• 4 to 16 Decoder
3 to 8 Decoder :
• The 3 to 8 decoder is one that has 3 input lines and 8 (23) output lines.
• The functional block diagram of the 3 to 8 decoder is shown in Figure-2.
• When this decoder is enabled with the help of enable input E, then it's one of the eight
outputs will be active for each combination of inputs.
• The operation of this 3-line to 8-line decoder can be analysed with the help of its
function table which is given below.
Using this function table, we can derive the Boolean expression for each output as follows –
As we can see, each output term contains products of input variables, hence they can be
implemented with the help of AND gates. Therefore, the logic circuit diagram of the 3 to 8
decoder is shown in Figure-5.
Operation: