Priority Encoder Explained: 4-to-2 and 8-to-3
Derive 4-to-2 and 8-to-3 priority encoders, use a valid output, cascade groups, and account for glitches, asynchronous requests, and starvation.
TL;DR: A priority encoder returns the index of the highest-ranked active input and asserts a separate valid signal. A fixed-priority Boolean network resolves simultaneous requests, but it does not store pending requests, guarantee fairness, synchronize asynchronous inputs, or hold a grant. Those behaviors require logic around the encoder.
A plain encoder assumes its input is one-hot. If two inputs are active, its OR equations can produce a code for an input that was never asserted. A priority encoder removes that ambiguity by defining which active input wins.
That makes it useful for interrupt selection, arbitration, find-first-set operations, and event summarization. But “useful in an interrupt controller” is not the same as “is an interrupt controller.” The encoder is a combinational selection primitive; pending bits, masks, handshakes, and fairness are separate design responsibilities.
Define Priority, Polarity, and Validity
Assume four active-high inputs through , with the larger index having higher priority:
Outputs contain the winning index. V indicates that at least one request exists.
| V | Winner | |||||
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | xx | 0 | none |
| 0 | 0 | 0 | 1 | 00 | 1 | |
| 0 | 0 | 1 | x | 01 | 1 | |
| 0 | 1 | x | x | 10 | 1 | |
| 1 | x | x | x | 11 | 1 |
Lower inputs are don’t-cares after a higher input is active. The output code is also a don’t-care when V=0. V is essential because winner 0 and “no winner” would otherwise both appear as 00.
Other interfaces may use:
- lowest index as highest priority;
- active-low request inputs;
- active-low encoded outputs;
- a defined zero code instead of don’t-care when idle;
- one-hot grant output in addition to or instead of an index.
The function table, not the block’s name, is the contract.
Why a Plain Encoder Fails
A one-hot 4-to-2 encoder uses:
If only , the output is 10. If only , it is 01.
But if , the equations return 11, falsely pointing to . The circuit has not malfunctioned; its one-hot input assumption was violated.
A priority encoder defines a result for every many-hot input combination.
Deriving the 4-to-2 Network
One clean derivation forms one-hot winner signals:
At most one W signal can be high. The binary encoder now operates on a guaranteed one-hot vector:
Boolean simplification gives the familiar direct equations:
The winner-mask form is often easier to verify and extend. The simplified form may use less logic in a particular implementation.
Scaling to 8-to-3
For inputs through , define:
says input i is active and every higher-priority input is inactive.
Then:
The index bits are OR reductions of winner positions whose binary index contains that bit:
This description is exact but a literal linear mask can become deep. Synthesis may factor common terms or use a hierarchical prefix network.
Hierarchical implementation
Split the requests into high and low groups:
high group: I7…I4
low group: I3…I0
Run a 4-to-2 encoder on each group. If V_high=1, choose the high group’s two-bit result and set . Otherwise choose the low group and set :
This decomposition exposes the same priority at two levels and scales to wider trees.
The SN74HC148 Convention
The SN74HC148 is an eight-line-to-three-line priority encoder with enable signals intended for cascading. Its interface uses active-low conventions, so an asserted input and its encoded output do not match the active-high equations above without inversion and careful reading of the function table.
When using a physical part:
- identify every active-low bubble;
- obey the enable-input condition;
- use group/enable outputs as specified for cascading;
- check output drive and fan-out;
- use maximum, not typical, propagation delays for timing limits.
The logical idea is the same, but polarity errors are among the most common mistakes when moving from a textbook encoder to a 74x148-family device.
Timing, Glitches, and Sampling
A combinational priority encoder has no sampling edge and no memory. When requests change, internal paths settle after different delays. The encoded bits and V can pass through temporary combinations.
For example, if deasserts while is already active, the output should move from 111 to 010. The three result bits need not switch simultaneously in physical hardware.
Choose an interface strategy:
- register requests, then encode them;
- register the code and V together after sufficient combinational delay;
- convert the winner to a one-hot grant and capture it;
- use a request/grant handshake so the selected requester remains stable;
- use hazard-aware asynchronous design if there is deliberately no clock.
Do not feed asynchronous external requests directly into a synchronous control path and assume the encoder removes metastability. Each asynchronous request needs an appropriate synchronization or asynchronous-interface scheme. A multi-bit request vector may also need event capture so short pulses are not lost.
Fixed Priority and Starvation
The Boolean network above is fixed priority. If remains asserted, can wait forever.
That may be correct for a safety-critical alarm that must dominate routine traffic. It may be unacceptable for a shared bus.
Fair policies require state:
- round-robin rotates the first candidate after each grant;
- aging increases priority with wait time;
- weighted arbitration gives requesters configured service shares;
- hierarchical schemes combine class priority with fairness within a class.
A stateless encoder cannot implement those policies by itself.
Where Priority Encoders Fit
Interrupt selection
An interrupt controller can combine:
eligible = pending AND enable AND NOT masked
then priority-encode eligible. The controller must also retain pending events, apply programmable priority rules, route the interrupt, acknowledge service, and handle concurrent arrival and completion. The encoder performs only the “which eligible source ranks first?” step.
Bus arbitration
Requests feed a priority resolver; its one-hot winner can become a grant after being registered. A complete arbiter also defines when ownership begins and ends, how a requester acknowledges the grant, and whether the policy prevents starvation.
Encoding to binary and immediately decoding back to one-hot can be useful when the index must travel through a narrow interface. If only a local grant is needed, a direct one-hot priority network may avoid redundant conversion.
Find-first-set and leading-zero functions
Finding the highest or lowest set bit is a priority-encoding problem. Processor instruction sets may expose count-leading-zero, count-trailing-zero, or bit-scan operations. Their hardware implementation can use hierarchical encoders, arithmetic transformations, lookup structures, or other optimized logic; cycle count and availability are architecture-specific.
Multiple key inputs
A priority encoder can intentionally reduce simultaneous keys to one result. That is appropriate only if losing lower-priority key information is part of the specification. A keyboard that needs multi-key rollover must preserve the full matrix state instead. Diodes address electrical ghost paths; they do not change a priority encoder’s information loss.
Cascading Correctly
Two active-high 4-to-2 blocks can form an 8-to-3 encoder:
| V | source | |||
|---|---|---|---|---|
| 1 | x | 1 | 1 | high group |
| 0 | 1 | 1 | 0 | low group |
| 0 | 0 | 0 | x | don’t-care |
This table makes the priority boundary explicit. It also provides a reusable verification property: low-group input changes must not affect the code while any high-group input is active.
With packaged encoders, use their dedicated cascade signals rather than assuming their V/EO/GS labels and polarities match this abstract block.
Build and Verify It in DigiSim
Start with the 4-to-2 priority encoder template:
- Implement through .
- Confirm the W vector is one-hot-or-zero for all 16 input patterns.
- Encode W into O and generate V.
- Compare the result with the simplified equations.
- Cascade two four-input groups into an eight-input design.
Then verify:
- no requests gives V=0;
- every single request returns its own index;
- every pair returns the higher-priority index;
- all inputs high returns the configured top priority;
- low inputs cannot affect the result while a high-group request exists;
- code and V are captured together if a register is added.
For an eight-input design, exhaustive checking requires only 256 request patterns. Add assertions:
and, whenever V=1, the output index names an asserted input with no asserted input above it.
Functional simulation verifies the Boolean priority rule. It does not prove asynchronous safety, pulse capture, electrical timing, or fairness.
Continue with decoders and encoders for the one-hot/binary relationship, or multiplexers to route data from the selected source.



