Decoders and Encoders: Driving a 7-Segment Display
Digital Logic 101
📅 January 2026 • ⏱️ 16 min read • 🎓 Beginner-Intermediate
How does a calculator show numbers? How does a digital clock display the time? The answer involves decoders—circuits that translate binary codes into human-readable outputs. In this tutorial, you'll build a 7-segment display driver and understand the encoder/decoder relationship.
What is a Decoder?
A decoder takes an n-bit binary input and activates one of 2ⁿ output lines. It "decodes" a binary number into a specific action or output.
Decoder: Binary to Unique Output
Input: n-bit binary code
Output: 2ⁿ output lines, exactly ONE is active at a time
Example: 2-to-4 decoder: 2 inputs → 4 outputs (one hot)

A 2-to-4 decoder: the 2-bit input selects which of 4 outputs is HIGH. Input 10 (binary 2) activates output Y₂.
The 7-Segment Display
A 7-segment display shows decimal digits using seven LED segments arranged in a figure-8 pattern. Each segment is labeled a through g:
━━━━━ (a)
│ │
(f) (b)
│ │
━━━━━ (g)
│ │
(e) (c)
│ │
━━━━━ (d)

A BCD to 7-segment decoder: 4-bit binary input produces 7 outputs to control each segment.
BCD to 7-Segment Truth Table
BCD (Binary Coded Decimal) uses 4 bits to represent digits 0-9. The decoder maps each digit to the appropriate segment pattern:

Complete BCD to 7-segment decoder with active display showing the digit "5".
Key Insight: It's NOT a Simple Decoder!
A 7-segment decoder is different from a standard binary decoder. A 4-to-16 decoder activates ONE output at a time. A 7-segment decoder activates MULTIPLE segments simultaneously (digit "8" lights all 7 segments). It's really a combinational logic circuit with 7 separate outputs, each with its own Boolean equation.
What is an Encoder?
An encoder is the opposite of a decoder: it takes 2ⁿ inputs (one active) and outputs the n-bit binary code for that input.
Decoder
Direction: Binary → One-hot
Input: n bits
Output: 2ⁿ lines
Example: Address to memory chip select
Encoder
Direction: One-hot → Binary
Input: 2ⁿ lines
Output: n bits
Example: Keyboard key to scan code

A 4-to-2 priority encoder: when multiple inputs are active, it encodes the HIGHEST priority one.
Priority Encoders
What if multiple encoder inputs are active simultaneously? A priority encoder solves this by encoding only the highest-priority (usually highest-numbered) active input.
The X means "don't care"—lower-priority inputs are ignored when a higher-priority input is active.
Applications
🖥️ Memory Address Decoding
CPU address lines feed a decoder that selects which memory chip or I/O device to access.
⌨️ Keyboard Encoding
When you press a key, a priority encoder converts the key's position to a binary scan code.
🚦 Interrupt Handling
Multiple interrupt requests → priority encoder → highest-priority interrupt served first.
📟 Display Systems
7-segment decoders drive calculators, clocks, appliance displays, and scoreboards.
Building a 3-to-8 Decoder

A 3-to-8 decoder using AND gates. Each output requires a unique combination of inverted/non-inverted inputs.
Try It Yourself!
- Build a 2-to-4 decoder: Use 4 AND gates with appropriate inversions
- Wire a 7-segment display: Connect the decoder outputs to light segments
- Create a 4-to-2 encoder: Encode 4 buttons to 2-bit binary
- Add priority: Modify your encoder to handle multiple pressed buttons
© 2026 DigiSim.io — The Interactive Digital Logic Simulator
digisim.io • Blog • Lessons