Encoder and Decoder:
1. The Digital Language Barrier
Computers only understand one language: Binary (1s and 0s).
Humans understand many things: Numbers, letters, words, and actions (like pressing a button).
How do we talk to each other?
o We need translators!
o Encoders and Decoders are the digital circuits that act as these translators.
Example: Think of sending a secret message.
o Encoder: You take your message ("Attack at dawn") and turn it into a secret code (Ciphertext).
o Decoder: Your friend receives the code and turns it back into the original message.
The Encoder
An encoder is a digital combinational circuit that converts multiple input signals into a binary code. It typically
has one active input at a time and generates a binary output representing the position of that active input.
The number of inputs is usually 2n, with n output lines.
Inputs are usually active high, meaning high voltage represents an active signal.
Encoders help convert parallel inputs into compact binary formats for processing.
Encoders are useful in digital systems for data compression and efficient transmission.
For example, a 4-to-2 encoder has four inputs and produces a 2-bit output code.
Slide 8: The 4-to-2 Line Encoder -
It has:
o 4 Inputs: Representing 4 different events or buttons (I0, I1, I2, I3).
o 2 Outputs: The binary code representing which input was active (A, B).
4-to-2 Encoder - Truth Table
This table shows how we compress 4 inputs down to 2 outputs.
Assumption: Only one input can be active (HIGH) at a time.
Y3 Y2 Y1 Y0 A1 A0 Meaning (Binary Output)
0 0 0 1 0 0 Y0 is active -> Output "00"
0 0 1 0 0 1 Y1 is active -> Output "01"
0 1 0 0 1 0 Y2 is active -> Output "10"
1 0 0 0 1 1 Y3 is active -> Output "11"
Notice: We don't output a 1 on a specific line. We output a binary number that tells us which line
was 1.
A1 = Y3 + Y2
A0 = Y3 + Y1
Circuit diagram:
8-to-3 Encoder: Block Diagram:
Truth Table:
Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 A2 A1 A0
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 0 0 0 1 1
0 0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 1
0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1
Circuit Daigram:
A2 = Y7 + Y6 + Y5 + Y4
A1 = Y7 + Y6 + Y3 + Y2
A0 = Y7 + Y5 + Y3 + Y1
Slide 10: Encoder - Real-World Example
Scenario: Your computer keyboard has over 100 keys. The computer doesn't have 100 separate wires
coming from it.
How an encoder helps:
1. When you press the key 'g' , a circuit closes.
2. This acts as an input to a big Encoder chip.
3. The encoder's job is to answer: "Which key was pressed?".
4. It instantly outputs a unique 8-bit binary number (a scan code) for the letter 'g'. For
example, 01100111.
5. This single 8-bit number travels down the keyboard cable to your computer, which then knows
you pressed 'g'.
2. The Decoder
A decoder is a combinational circuit that performs the reverse operation of an encoder, converting n input
lines into 2ⁿ output lines, with only one output active for each input combination.
What does it do?
o It decodes (translates) a binary number into a specific, unique output.
o Input: A small binary number (e.g., 10).
o Output: It "activates" one specific line out of many.
Example: The Mailroom
o Imagine a mailroom in a large apartment building with 4 apartments (Apt 00, Apt 01, Apt 10, Apt
11).
o A package arrives with a room number in binary (e.g., 10).
o The mailroom clerk (the Decoder) looks at the binary number and puts the package in the
mailbox for only that apartment.
Slide 4: The 2-to-4 Line Decoder - The Workhorse
This is the most common and simple decoder.
It has:
o 2 Inputs: Representing a 2-bit binary number (let's call them A and B. A is the Most Significant
Bit, B is the Least Significant).
o 4 Outputs: One for each possible combination of the inputs (0 through 3). We name them Y0,
Y1, Y2, Y3.
o Enable Pin (E): Think of this as an ON/OFF switch for the whole decoder. If Enable is OFF, all
outputs are OFF. If Enable is ON, it works as described.
2-to-4 Decoder
-
Truth Table
This table tells us everything we need to know. When Enable = 1 (ON):
E A B Y3 Y2 Y1 Y0 What it means
0 X X 0 0 0 0 Decoder is OFF
1 0 0 0 0 0 1 Input "00" selects Y0
1 0 1 0 0 1 0 Input "01" selects Y1
1 1 0 0 1 0 0 Input "10" selects Y2
1 1 1 1 0 0 0 Input "11" selects Y3
Notice: For any given input, only one output is HIGH (1). The rest are LOW (0).
Y0=E⋅A’⋅B’ Y1=E⋅A’⋅B
Y2=E⋅A⋅B’ Y3=E⋅A⋅B
The operation of logic circuit of the 2 to 4 decoder is described as follows −
When enable input (E) is inactive, i.e. set to 0, none of the AND gates will function.
When enable input (E) is made active by setting it to 1, then the circuit works as explained below.
When A = 0 and B = 0, the AND gate 1 becomes active and produces output Y0.
When A = 0 and B = 1, the AND gate 2 becomes active and produces output Y1.
When A = 1 and B = 0, the AND gate 3 becomes active and produces output Y2.
When A = 1 and B = 1, the AND gate 4 becomes active and produces output Y3.
3 to 8 Decoder
Truth Table:
Inputs Outputs
E A B C Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
0 X X X 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 1
1 0 0 1 0 0 0 0 0 0 1 0
1 0 1 0 0 0 0 0 0 1 0 0
1 0 1 1 0 0 0 0 1 0 0 0
1 1 0 0 0 0 0 1 0 0 0 0
1 1 0 1 0 0 1 0 0 0 0 0
1 1 1 0 0 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0
Y0=E.A’.B’.C’ Y1=E.A’.B’.C Y2=E.A’ .B.C’
Y3=E.A’.B.C Y4=E.A.B’.C’ Y5=E.A.B’.C
Y6=E.A.B.C’ Y7=E.A.B.C
Circuit diagram:
When enable input (E) is inactive, i.e. set to 0, none of the AND gates will function.
When enable input (E) is made active by setting it to 1, then the circuit works as described below.
When A = 0, B = 0, and C = 0, the AND gate 1 becomes active and produces output Y0.
When A = 0, B = 0, and C = 1, the AND gate 2 becomes active and produces output Y1.
When A = 0, B = 1, and C = 0, the AND gate 3 becomes active and produces output Y2.
When A = 0, B = 1, and C = 1, the AND gate 4 becomes active and produces output Y3.
When A = 1, B = 0, and C = 0, the AND gate 5 becomes active and produces output Y4.
When A = 1, B = 0, and C = 1, the AND gate 6 becomes active and produces output Y5.
When A = 1, B = 1, and C = 0, the AND gate 7 becomes active and produces output Y6.
When A = 1, B = 1, and C = 1, the AND gate 8 becomes active and produces output Y7.
Slide 6: Decoder - Real-World Example
Scenario: You have a vending machine that sells 4 types of drinks. You press a button (1, 2, 3, or 4).
The machine needs to release the correct drink.
How a decoder helps:
1. The button press is converted into a 2-bit binary number.
Button 1 = 00
Button 2 = 01
Button 3 = 10
Button 4 = 11
2. This binary number goes into the 2-to-4 Decoder.
3. The decoder's output (Y0, Y1, Y2, Y3) is connected to the release mechanism for each drink.
4. If you press Button 3 (10), only output Y2 goes HIGH, triggering the release mechanism for
Drink #3. The other drinks stay put.
Slide 11: A Small Problem & A Better Solution (Priority Encoder)
Problem with our simple Encoder: What if someone presses two buttons at once? Our simple truth
table didn't account for this. It would get confused and give a wrong output.
Solution: The Priority Encoder
o This is a smarter version. It has a built-in rule: "If multiple inputs are active, I will only pay
attention to the one with the highest priority."
o Usually, the highest-numbered input (e.g., I3) has the highest priority.
Slide 12: Summary - Decoder vs. Encoder
(Use a side-by-side comparison graphic)
Feature Decoder Encoder
Function Decodes / Unpacks Encodes / Packs
Input Small Binary Number One Active Line (among many)
Output One Active Line (among many) Small Binary Number
Analogy Mailroom Clerk Office Receptionist
Common Example 2-to-4 Line, 3-to-8 Line 4-to-2 Line, Priority Encoder
What it does Takes a code, tells you what it means Takes an event, gives you its code