8-to-3 Priority Encoder

Easy · Combinational Logic

Implement an 8-to-3 priority encoder.

Eight requesters share one resource. Each one raises its bit of req to ask for it. The encoder reports the index of the highest-numbered set bit of req (bit 7 has the highest priority, bit 0 the lowest) and whether any bit is set at all.

Ports

PortDirWidthMeaning
reqinput8Request vector, unsigned. Bit i set means requester i is asking.
idxoutput3Index (0–7) of the most significant 1 in req.
validoutput11 if at least one bit of req is set, otherwise 0.

When req is all zeros, there is no winner: valid must be 0 and idx must be 0 (a defined value, not "don't care").

The circuit is purely combinational: outputs follow req in the same time step, with no clock and no state.

Examples

req (binary)idxvalidWhy
0000_000000no request
0000_000101only bit 0 is set
0000_011021bits 2 and 1 are set; bit 2 wins
1000_000171bit 7 wins over bit 0
0101_000061bit 6 wins over bit 4

Hints

order of the loop: in a procedural block, the last assignment wins.

inferred and the all-zero case is defined.

Sign up free to solve 8-to-3 Priority Encoder in your browser.

More Combinational Logic problems