Decoders and encoders
A decoder turns a binary number into exactly one active wire: two input bits light one of four output lamps. Build a 2-to-4 decoder from two NOT gates and four AND gates, watch it pick a memory row and an operation, light the bars of a 7-segment digit, and then go the other way with an encoder, including the priority encoder that copes when several lines are on.
5 quick questions
Pick an answer to see why. Your score saves with your progress.
01A 2-to-4 decoder gets the input A1 A0 = 1 1. Which output is on?
1 1 is the number 3 (one 2 plus one 1), so only Y3 is on. The other three outputs stay at 0.
02What does one-hot mean?
In a one-hot pattern exactly one line is 1. Each row of a decoder's truth table is one-hot.
03In a 2-to-4 decoder built from gates, which two rails does the AND gate for Y1 (input 0 1) tap?
Y1 must be 1 only when A1 is 0 and A0 is 1, so its AND gate taps NOT A1 (which is 1 when A1 is 0) and A0.
04Inputs I1 and I2 of a 4-to-2 priority encoder are both on. What does it output?
A priority encoder reports only the highest line that is on. That is I2, and 2 in binary is 1 0. A plain encoder would wrongly give 1 1.
05Why does a memory chip need a decoder?
The address bits go into a row decoder, and its one active output (the word line) selects a single row.
Glossary
- Decoder
- A circuit that turns an N-bit binary number into exactly one active output line out of 2^N.
- Encoder
- The reverse of a decoder: it turns one active input line into the binary number of that line.
- Priority encoder
- An encoder that, when several inputs are on, outputs the number of the highest one.
- One-hot
- A pattern of bits where exactly one is 1 and all the others are 0.
- Rail
- A long wire that carries one signal past many gates, so each gate can tap it.
- Word line
- The wire, driven by a decoder output, that selects one row of a memory array.
- 7-segment display
- A digit made of seven bars, named a to g, that light in different patterns to show 0 to 9.
- BCD
- Binary-coded decimal: one decimal digit, 0 to 9, written as a 4-bit binary number.
Notes and sources
- A 2-to-4 decoder needs two NOT gates and four 2-input AND gates; each AND gate matches one input pattern (Harris and Harris, Digital Design and Computer Architecture, section 2.8.2). In general N inputs give 2^N outputs.
- In a memory array the address goes into a decoder whose outputs are the word lines; the one active word line selects the row that is read or written (Harris and Harris, section 5.5).
- A real part: Texas Instruments' SN74HC139 holds two 2-to-4 decoders. Its outputs are active low: the chosen line goes to 0 and the others stay at 1, the same idea with the levels flipped.
- The SN74HC148 is an 8-line to 3-line priority encoder: when several inputs are active it outputs the number of the highest one.
- 7-segment decoder chips such as TI's CD74HC4511 turn a 4-bit number (BCD) into the seven bar signals. Chips differ on whether 6 and 9 get the extra top or bottom bar; the figure draws them with it.
- In Python a decoder is [int(n == i) for i in range(4)], an encoder is y.index(1), and a priority encoder is max(i for i in range(4) if x[i]).
- Harris and Harris, Digital Design and Computer Architecture (section 2.8.2 decoders, section 5.5 memory arrays)
- Texas Instruments SN74HC139 datasheet: dual 2-line to 4-line decoders/demultiplexers
- Texas Instruments SN74HC148 datasheet: 8-line to 3-line priority encoders
- Texas Instruments CD74HC4511 datasheet: BCD-to-7 segment latch/decoder/driver
- MIT OpenCourseWare 6.004 Computation Structures
- Python tutorial: data structures (list comprehensions, list.index)
Quiz Unlocks after the last step.