HDLbits
Start Practicing

Circuits/Combinational Logic

BCD to 7-Segment Display Decoder

medium
decoder7-segmentbcdcombinational

A 7-segment display shows a digit by illuminating a subset of seven segments, labeled a through g:

 _a_
f|   |b
 |_g_|
e|   |c
 |_d_|

Build a decoder that takes a 4-bit BCD digit (0-9) and drives the segment outputs so the display shows the corresponding digit. The output is packed as seg = {g, f, e, d, c, b, a} (bit 0 is segment a, bit 6 is segment g), and a segment is on when its bit is 1.

Interface

Signal Direction Width Description
bcd input 4 BCD digit, 0-9 (10-15 are invalid / don’t-care)
seg output 7 Segment drive, {g,f,e,d,c,b,a}, active-high

Segment truth table

bcd a b c d e f g
0 1 1 1 1 1 1 0
1 0 1 1 0 0 0 0
2 1 1 0 1 1 0 1
3 1 1 1 1 0 0 1
4 0 1 1 0 0 1 1
5 1 0 1 1 0 1 1
6 1 0 1 1 1 1 1
7 1 1 1 0 0 0 0
8 1 1 1 1 1 1 1
9 1 1 1 1 0 1 1

Inputs 10-15 never occur in valid BCD, so their output is a don’t-care — driving all segments off is a reasonable default.