A priority encoder is an encoder with a rule for crowds. When several inputs are 1 at once, it reports only the one with the highest priority and ignores the rest. Usually the highest-numbered input wins, but a design can rank them any way.
It also has a valid bit V = 1 whenever at least one input is active. Without V, "only D0 active" and "nothing active" would both output 00.
For a 4-to-2 priority encoder with D3 highest:
- Y1 =
- Y0 =
- V =
The in Y0 is the priority at work: D1 may only set Y0 when D2 isn't active, because D2 outranks it.
Filling its truth table is quickest in blocks, from the top priority down. Every row with D3 = 1 outputs 11, whatever the other bits are. Then every row with D3 = 0 and D2 = 1 outputs 10, and so on.
Where it shows up: interrupt controllers (several devices ask the CPU for attention; the most urgent is served first) and keyboards (several keys pressed together).