5.4 Decoders, Encoders & Priority Encoders
π‘ Core Intuition: The Postal Routing Hub & The Emergency Dispatcherβ
Imagine an automated postal logistics hub receiving packages marked with a 3-bit binary postal code (). An automated robotic arm reads the code and routes the package into exactly one of eight designated sorting chutes ( through ). This is a Decoder: it expands an -bit compressed coded address into unique activation lines.
π³ The Everyday Analogy: The 911 Emergency Dispatcherβ
Now consider the inverse scenario. An emergency call center receives incoming alerts from multiple city alarm sensors:
- Sensor 0: Minor water leak.
- Sensor 1: Power grid fluctuation.
- Sensor 2: Commercial robbery.
- Sensor 3: High-rise hospital fire.
If multiple emergencies trigger simultaneously, the dispatcher cannot scramble responders randomly or combine codes into nonsense. A strict Priority Protocol enforces that the hospital fire (highest priority) completely overrides all lesser alarms. The dispatcher transmits the binary code of the highest-severity event while asserting an "Active Emergency" beacon. This is a Priority Encoder.
π» Bridging to Computer Scienceβ
Decoders and Priority Encoders are foundational building blocks in computing systems:
- Memory Address Decoders: When a CPU writes to memory address
0x3F80, high-order address bits route through a decoder to assert the Chip Select () pin of one specific 8GB RAM chip while keeping all other chips in low-power sleep. - Instruction Decoders: Inside a CPU core, the instruction decoder decodes 32-bit machine code opcodes (like
0110011for RISC-VADD) to activate the appropriate ALU datapath multiplexers and write-enable lines. - Hardware Interrupt Controllers: When a network packet arrives, a keyboard key is pressed, and a timer ticks simultaneously, the CPU's Programmable Interrupt Controller (PIC / APIC / ARM GIC) uses a priority encoder to present the highest-priority Interrupt Request (IRQ) to the CPU execution core.
πTable of Contents
- ποΈ Decoder Fundamentals & The 74138 IC
- π³ Decoder Expansion & Tree Synthesis
- β‘ Function Realization via Minterm Generators
- π Demultiplexers (DEMUX) & Structural Duality
- π― Encoders & The Priority Resolution Problem
- π¨ Priority Encoder Architecture & K-Map Derivation
- π Real-World Production Context: Memory Address Decoding & Hardware Interrupt Controllers
- π Numerical Applications & Worked Examples
- π― Exam & Interview Pitfall Check
ποΈ Decoder Fundamentals & The 74138 ICβ
A Decoder is a combinational logic circuit that converts an -bit binary input code into a maximum of unique physical output lines.
1-of-2βΏ Activation
One-Hot / Zero-Hot- For any valid n-bit input code, exactly ONE output line is active at any given moment.
- Active-high decoders assert 1 on the selected line; active-low decoders assert 0.
Minterm Generation
Canonical Terms- Each output line corresponds to an individual minterm of the n input variables.
- Output k is asserted if and only if input code equals binary k.
Enable (Chip Select)
Strobe Gate- Enables expansion and bus interfacing.
- When disabled, ALL output lines are deactivated simultaneously.
The 2:4 Active-High Decoder with Enableβ
- Inputs: data inputs (), enable line ().
- Outputs: outputs ().
| Enable () | (MSB) | (LSB) | Active Minterm | ||||
|---|---|---|---|---|---|---|---|
| None (Disabled) | |||||||
| E | A | B | Yβ | Yβ | Yβ | Yβ |
|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
The 3:8 Active-Low Decoder (Industry Standard: 74138 IC)β
In industrial digital logic, active-low outputs are overwhelmingly preferred because bipolar TTL and CMOS NAND gates are physically faster and consume lower static power when pulling down to ground.
The classic 74138 (74HC138) features:
- Select Inputs: (LSB), , (MSB).
- Enable Inputs: (Active-High), (Active-Low), (Active-Low).
- Chip is enabled iff AND AND .
- Active-Low Outputs: .
When enabled ():
For example:
Only the selected output goes to Logic 0; all other seven outputs remain held high at Logic 1.
π³ Decoder Expansion & Tree Synthesisβ
To construct a wider decoder than available in standard IC packages, we cascade smaller decoders by using their Enable inputs to steer the most significant address bits.
Building a 3:8 Decoder Using Two 2:4 Decodersβ
- Inputs: 3 variables where is MSB, and are lower bits.
- Connect lower bits to the select lines of both 2:4 decoders.
- Use the MSB () to enable one decoder at a time:
- When : Enable the first decoder (covers outputs representing minterms ).
- When : Enable the second decoder (covers outputs representing minterms ).
3:8 Decoder Expansion Architecture Using Two 2:4 Decoders
Hierarchical steering: MSB address input A gates the enable pins while inputs B and C drive all lower decoders
MSB Address Steering (A)
Steers which of the two 2:4 sub-decoders is enabled.
Decoder #1 (Outputs Yβ..Yβ)
Evaluates (B, C) inputs when A = 0.
Decoder #2 (Outputs Yβ..Yβ)
Evaluates (B, C) inputs when A = 1.
General Sizing Formula for Decoder Treesβ
To construct an -to- decoder using -to- decoders (where ):
- The output stage requires decoders of size -to-.
- The enable inputs of these output decoders are driven by a preliminary decoding stage of size -to-.
For example, to build a 4:16 Decoder using 2:4 Decoders:
- Output stage: decoders (each handles 4 outputs).
- Control stage: decoder of size 2:4 (drives the enable inputs of the 4 output decoders).
- Total 2:4 Decoders required = .
β‘ Function Realization via Minterm Generatorsβ
Because an -to- decoder intrinsically evaluates all minterms, any arbitrary Boolean function in canonical Sum of Products (SOP) form can be synthesized simply by ORing the required minterm outputs!
Function Synthesis: Active-High vs. Active-Low Decoders
Comparing external combining gate requirements for canonical SOP logic synthesis
Active-High Decoder
Output pins assert Logic 1 for selected minterm: Y_k = m_k.
Active-Low Decoder (74138)
Output pins assert Logic 0 for selected minterm: YΜ_k = mΜ_k.
Let a function be defined as .
An active-low decoder (like the 74138) provides inverted minterms on its output pins:
Connect these active-low outputs to the inputs of an external NAND gate:
Conclusion: Any arbitrary Boolean function can be implemented using an active-low decoder combined with a single NAND gate, requiring zero external inverters!
π Demultiplexers (DEMUX) & Structural Dualityβ
A Demultiplexer (DEMUX) is the functional inverse of a Multiplexer:
- It takes data input line () and steers it to one of output lines () selected by control select lines ().
The Formal Identity Between Decoders and DEMUXesβ
There is zero structural difference between a Decoder with an Enable line and a Demultiplexer:
- In a Decoder, the Enable input is treated as a control strobe, and the select lines are inputs.
- In a Demultiplexer, the Enable pin is used as the Data Input ()!
- When , the selected output line asserts (while all others remain ).
- When , all output lines remain .
Interactive 1:4 Demultiplexer (DEMUX) Hardware Lab
Toggle select lines (Sβ, Sβ) and input data stream (Din) to observe live data steering across the 4 output lines.
π― Encoders & The Priority Resolution Problemβ
An Encoder performs the inverse operation of a decoder: it takes (or fewer) input lines and compresses them into an -bit binary output code.
The Standard Binary Encoder (Octal-to-Binary: 8-to-3)β
Assumes that exactly one input line is asserted at any time:
| Active Input | (MSB) | (LSB) | |
|---|---|---|---|
Equations:
| Active Line | Yβ | Yβ | Yβ | Yβ | Aβ | Aβ |
|---|---|---|---|---|---|---|
| Yβ only | 0 | 0 | 0 | 1 | 0 | 0 |
| Yβ only | 0 | 0 | 1 | 0 | 0 | 1 |
| Yβ only | 0 | 1 | 0 | 0 | 1 | 0 |
| Yβ only | 1 | 0 | 0 | 0 | 1 | 1 |
The Two Fatal Flaws of Standard Encodersβ
A naive binary encoder fails catastrophically in real-world computer systems due to two fundamental ambiguities:
- The "All-Zero" Ambiguity:
If all input lines are (), the circuit outputs .
Notice that this output is identical to the code produced when input ! The processor cannot distinguish between "Device 0 requested service" and "No device requested service." - Multiple Simultaneous Assertions:
If both and are asserted simultaneously:
The circuit outputs the code for device , even though device 6 never requested anything!
To resolve these fatal flaws, engineers invented the Priority Encoder.
π¨ Priority Encoder Architecture & K-Map Derivationβ
A Priority Encoder establishes a strict hierarchy among inputs (by convention, higher-indexed inputs have higher priority). If multiple inputs are asserted at once, the circuit outputs the binary code of the highest-priority active line.
It also introduces an essential output flag:
- Valid Bit () / Group Select (): Asserts logic if at least one input line is active, and logic if all inputs are inactive.
Truth Table of a 4-to-2 Priority Encoderβ
Let inputs be , where has the highest priority and has the lowest priority:
| (Highest) | (Lowest) | (MSB) | (LSB) | Valid Flag () | ||
|---|---|---|---|---|---|---|
- denotes "Don't Care" (the input state is irrelevant because a higher-priority line dominates).
K-Map Minimization for 4:2 Priority Encoderβ
Derivation of Valid Bit ():
is whenever any input line is active:
Derivation of Output :
must be when (regardless of all others) OR when (provided ):
Derivation of Output :
must be when OR when ( AND AND ):
- Output Logic: 2-input OR gate taking and .
- Output Logic: 2-input AND gate computing , feeding into a 2-input OR gate with .
- Valid Flag Logic: 4-input OR gate taking all lines .
| Dβ | Dβ | Dβ | Dβ | Yβ | Yβ | V |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | Γ | Γ | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | Γ | 0 | 1 | 1 |
| 0 | 1 | Γ | Γ | 1 | 0 | 1 |
| 1 | Γ | Γ | Γ | 1 | 1 | 1 |
π Real-World Production Context: Memory Address Decoding & Hardware Interrupt Controllersβ
In modern computer architecture, decoders and priority encoders form the foundational hardware layer connecting processors with volatile memory and asynchronous peripherals.
Microprocessor Memory Mapping & Interrupt Handling Subsystem
High-Order Address Lines (A15-A13)
CPU asserts 16-bit address during memory fetch. Top 3 bits feed a 3:8 decoder (74138) to select a specific 8 KB page.
Bank Selection via Active-Low Decoders
Active-low outputs (/Y0 to /Y7) connect to the /CS lines of SRAM, ROM, and Memory-Mapped I/O, activating exactly one target.
Priority Interrupt Controller (8:3 Priority Encoder)
Peripherals assert asynchronous IRQ lines. Priority encoder instantly outputs highest-priority vector to CPU.
CPU Interrupt Service Routine (ISR)
The core pushes program state, loads the vector table address from the encoder output, and services the critical event.
- Memory Address Decoding: When a CPU addresses physical memory, the higher-order address lines determine which memory device or peripheral is enabled, while the lower-order address lines specify the specific memory cell inside that chip. The 3:8 active-low decoder ensures mutually exclusive chip-select assertion, preventing electrical bus contention.
- Interrupt Resolution: When multiple real-time external events arrive simultaneously (such as a power failure alert, timer tick, and network packet), an internal priority encoder immediately forwards the critical interrupt vector to the CPU with hardware latency.
π Numerical Applications & Worked Examplesβ
Example 1: Full Adder Realization Using 74138 (Active-Low Decoder) & NAND Gatesβ
Problem Statement:
Synthesize a 1-bit Full Adder () using a single 3:8 active-low Decoder (74138) and the minimum number of external logic gates. Show the connection schematic and write the algebraic validation.
Step 1: Identify Canonical Mintermsβ
For a Full Adder with inputs :
- Sum:
- Carry Out:
Step 2: Interface to 74138 Decoderβ
- Connect address inputs: (MSB), , (LSB).
- Enable inputs: Tie , , to permanently enable the IC.
- The 74138 outputs produce inverted minterms: .
Step 3: Select External Combining Gatesβ
Using the property :
- Sum Output ():
Route outputs into a 4-input NAND gate: - Carry Output ():
Route outputs into a second 4-input NAND gate:
Total Components: Exactly 74138 Decoder and 4-input NAND gates.
Example 2: Synthesizing a 4:16 Decoder Using 2:4 Decodersβ
Problem Statement:
- Determine the exact number of 2:4 Decoders with active-high Enable inputs required to construct a 4:16 Decoder.
- Specify the wiring diagram showing how primary input address lines are partitioned.
- If each 2:4 Decoder has a propagation delay of , calculate the total latency of the 4:16 Decoder system.
Step 1: Determine Module Countβ
- A 4:16 Decoder has input lines and output lines.
- Each 2:4 Decoder produces outputs.
- To produce outputs, we need in the output stage.
- To steer the enables of these 4 decoders, we need an additional Decoder of size 2:4 in the input stage.
- Total 2:4 Decoders required = .
Step 2: Wiring Architectureβ
- Input Stage Decoder ():
- Inputs: Connected to the most significant address bits .
- Enable: Tied to (or master chip enable).
- Outputs: .
- Output Stage Decoders ():
- Inputs of all four decoders: Connected in parallel to the least significant address bits .
- Enable lines:
- Enable driven by decodes (outputs ).
- Enable driven by decodes (outputs ).
- Enable driven by decodes (outputs ).
- Enable driven by decodes (outputs ).
Step 3: Latency Calculationβ
- Signal propagation flows through (Stage 1) and then through the selected output decoder (Stage 2).
- Total propagation delay:
Example 3: 8-to-3 Priority Encoder Analysis & Expansionβ
Problem Statement:
An 8-to-3 Priority Encoder has inputs ( highest priority) and outputs plus Valid flag .
- Derive the simplified Boolean equations for , and .
- Determine the exact output code and flag status if the input vector applied is:
Step 1: Derive Output Equationsβ
Following priority resolution rules where masks all lower-order bits ( for ):
- Valid Bit ():
- Output (Asserted for inputs 4, 5, 6, 7):
- Output (Asserted for inputs 2, 3, 6, 7):
- Output (Asserted for inputs 1, 3, 5, 7):
Step 2: Evaluate Input Vector β
Inspect the active input lines from highest to lowest index:
- HIGHEST ACTIVE LINE!
- (Masked by )
- (Masked by )
- (Masked by )
Because is the highest active bit:
- The circuit ignores lines .
- Binary output code corresponding to index :
- Valid flag: At least one bit is active .
Final Output: with .
π― Exam & Interview Pitfall Checkβ
-
Why can an active-low Decoder implement multi-output functions with fewer total transistors than an active-high Decoder?
An active-high decoder requires OR gates to sum minterms (). An active-low decoder uses NAND gates (). In CMOS silicon fabrication, a NAND gate requires series NMOS and parallel PMOS transistors, which have higher electron mobility and lower parasitic capacitance than the series PMOS transistors required by NOR/OR gates. Thus, active-low NAND logic is physically faster and more compact. -
What is the purpose of the Cascade Input / Output pins (EI, EO, GS) on the 74148 8-to-3 Priority Encoder IC?
They allow seamless expansion to 16-to-4 or 64-to-6 priority encoders without external logic gates! The Enable Input () enables the chip. If no inputs on the high-order chip are active, its Enable Output () goes low, which automatically activates the lower-order priority encoder chip. The Group Select () pin serves as the Valid bit.
- Trap: Forgetting that a Demultiplexer cannot generate multiple outputs simultaneously.
Beginners sometimes confuse a DEMUX with a broadcast splitter. A 1-to- DEMUX connects its input line to only ONE selected output line at any time; all unselected outputs remain held at their inactive state. - Trap: Neglecting the Valid flag when interpreting Priority Encoder outputs.
If , you CANNOT declare that input is active without checking ! If , all inputs are completely inactive, and is simply a floating don't-care artifact.