8-to-3 priority encoder: truth table and circuit, live
An 8-to-3 priority encoder outputs the 3-bit number of the highest active input among D7 to D0, ignoring every lower one, plus a valid bit V that is 1 when any input is active. With D5 and D2 both on, the output is 101: input 5 wins.
A plain 8-to-3 encoder assumes one input at a time and ORs the codes together when there are more. A priority encoder settles conflicts by rank, which is what an interrupt controller or a keyboard scanner needs. Each output bit is the high-priority inputs that set it, plus lower inputs only when everything above them is off: Y2 = D7 + D6 + D5 + D4; Y1 = D7 + D6 + D5'D4'(D3 + D2); Y0 = D7 + D6'D5 + D6'D4'D3 + D6'D4'D2'D1. The valid bit tells "D0 is active" (output 000, V = 1) apart from "nothing is active" (000, V = 0). The same logic, with active-low inputs and outputs and enable pins for chaining, is the job of the classic 74148 chip. The 4-to-2 priority encoder is the smaller version.
Open this circuit in the lab →
What you need
- 4× NOT: D6', D5', D4' and D2'
- 7× AND: the priority conditions: D5'D4', D5'D4'(D3 + D2), D6'D5, D6'D4', D6'D4'D3, D6'D4'D2' and D6'D4'D2'D1
- 11× OR: the three outputs and V
Step by step
- Place inputs
D7(highest priority) toD0and probesY2,Y1,Y0andV. - Y2 = D7 + D6 + D5 + D4: any input of 4 or more wins over all of 0 to 3, so no priority logic is needed.
- Y1 = D7 + D6 + D5'D4'(D3 + D2): inputs 3 and 2 only count when 5 and 4 are off.
- Y0 = D7 + D6'D5 + D6'D4'D3 + D6'D4'D2'D1, and V = the OR of all eight. Turn on several inputs: the output always names the highest.
8-to-3 priority encoder truth table
| Highest active input | Y2 | Y1 | Y0 | V |
|---|---|---|---|---|
| none | 0 | 0 | 0 | 0 |
| D0 | 0 | 0 | 0 | 1 |
| D1 (any lower) | 0 | 0 | 1 | 1 |
| D2 (any lower) | 0 | 1 | 0 | 1 |
| D3 (any lower) | 0 | 1 | 1 | 1 |
| D4 (any lower) | 1 | 0 | 0 | 1 |
| D5 (any lower) | 1 | 0 | 1 | 1 |
| D6 (any lower) | 1 | 1 | 0 | 1 |
| D7 (any lower) | 1 | 1 | 1 | 1 |
"Any lower" means the inputs below may be 0 or 1: they do not change the output. All 256 input combinations of the live circuit are checked against "the number of the highest active input" before the page is built.
You can also read the full theory in the lesson on the priority encoder. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
More builds: Selecting, routing and decoding
All 246 build guides, by topic
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.
Open the 8-to-3 priority encoder in the lab →Frequently asked
What is an 8 to 3 priority encoder?
A circuit with eight inputs and a 3-bit output that encodes the highest-numbered active input, ignoring lower ones, usually with a valid output that is 1 when any input is active.
What is the difference between an encoder and a priority encoder?
A plain encoder assumes exactly one input is active and gives a wrong code when several are. A priority encoder always outputs the number of the highest active input.
What is the 74148?
The classic 8-line to 3-line priority encoder chip. It works like this circuit but with active-low inputs and outputs, plus enable input and output pins so several can be chained for more inputs.
Why does a priority encoder need a valid output?
Because input 0 and no input both produce the code 000. The valid bit V is 1 only when at least one input is active, so the two cases can be told apart.