Priority Encoder - 3bits

AMD

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-priority 1


📌 Functional Requirements

Input (in)

Explanation

Output (pos)

000

No bits set

00

001

Bit 0 is set

00

010

Bit 1 is set

01

011

Bit 1 has higher priority than bit 0

01

100

Bit 2 is set

10

111

Bit 2 has highest priority

10


⚠️ 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.

Output

Output goes here...