Priority Encoder - 3bits

Problem Description
🧠 Problem Description
A priority encoder encodes the position of the highest-priority asserted bit in an input vector.
You are required to design a 3-bit priority encoder in Verilog.
Priority Rule
Bit 2 has the highest priority
Then bit 1
Then bit 0
The encoder must output the index of the highest set bit.
If no bits are set, the output must be 0.
📥 Inputs
in [2:0]— 3-bit input vector
📤 Outputs
pos [1:0]— Encoded position of the highest-priority1
📌 Functional Requirements
Input ( | Explanation | Output ( |
|---|---|---|
| No bits set |
|
| Bit 0 is set |
|
| Bit 1 is set |
|
| Bit 1 has higher priority than bit 0 |
|
| Bit 2 is set |
|
| Bit 2 has highest priority |
|
⚠️ Notes
Design should be purely combinational
No latches or clocks allowed
Must work for all 8 possible input combinations
Verilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
