Priority Encoder
Design an 8-to-3 priority encoder where bit 7 has the highest priority.
Task
Return the index of the highest set input bit and a valid flag.
Examples
- in=8'b00101000 → index=5, valid=1
- in=0 → valid=0
Constraints
- Bit 7 has highest priority.
- Output valid must be 0 when all inputs are 0.
What this problem is testing
A strong answer translates the requirement into synthesizable state and combinational logic, states reset and update semantics precisely, and handles boundary conditions rather than only the nominal case.
Interview habit: before coding, state reset behavior, the state that must be stored, and the conditions that update each output.
Verification plan
- Check reset or initialization before normal operation.
- Exercise the nominal sequence cycle by cycle.
- Test boundaries such as zero, maximum count, wraparound, full/empty, or simultaneous controls when they apply.
- Prove the design holds state when an enable or qualifying condition is absent.
Common mistakes
- Incomplete combinational assignments that infer a latch.
- Blocking/non-blocking assignments that do not match combinational versus sequential intent.
- Parameter-width and boundary errors.
- Passing the happy path while missing reset, overflow, simultaneous operations, or illegal requests.
Interview follow-up questions
- How would you parameterize this design without introducing width or boundary bugs?
- What changes if reset timing or polarity changes?
Concepts to review
combinational, encoder
Open Priority Encoder in the HDLForge interactive editor.
Related problems
- 2:1 Multiplexer — Easy
- Parameterized Counter — Easy
- Synchronous FIFO — Hard
- Shift Register — Easy
- Rising Edge Detector — Easy
Explore the RTL Design Practice & Interview Preparation hub.