Decoders and Encoders: Driving a 7-Segment Display

Denny Denny
4 min read

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?

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)

2-to-4 Decoder lesson

A 2-to-4 decoder: the 2-bit input selects which of 4 outputs is HIGH. Input 10 (binary 2) activates output Y₂.

A₁A₀Y₀Y₁Y₂Y₃
001000
010100
100010
110001

The 7-Segment Display

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)

BCD to 7-Segment Decoder lesson

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:

DigitDCBAabcdefg
000001111110
100010110000
200101101101
300111111001
401000110011
501011011011
601101011111
701111110000
810001111111
910011111011
BCD to 7-Segment Decoder template

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

4-to-2 Priority Encoder lesson

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.

D₃D₂D₁D₀Y₁Y₀Output (Decimal)
0001000
001X011
01XX102
1XXX113 (highest priority)

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

3-to-8 Decoder lesson

A 3-to-8 decoder using AND gates. Each output requires a unique combination of inverted/non-inverted inputs.

Try It Yourself!

  1. Build a 2-to-4 decoder: Use 4 AND gates with appropriate inversions
  2. Wire a 7-segment display: Connect the decoder outputs to light segments
  3. Create a 4-to-2 encoder: Encode 4 buttons to 2-bit binary
  4. Add priority: Modify your encoder to handle multiple pressed buttons

© 2026 DigiSim.io — The Interactive Digital Logic Simulator

digisim.io • Blog • Lessons