RTL Design #34 · 2026-10-27 · Priority encoders · Easy · about 10 min
A priority encoder that favors the wrong end
prio_enc is a combinational priority encoder over req[W-1:0]. Bit 0 has the highest priority.
validis 1 whenenis 1 and at least one bit ofreqis set.idxis the number of the lowest set bit ofreq. It is 0 when no bit is set.grantis one-hot: only the lowest set bit ofreq, or all zeros ifenis 0.Wis not always a power of two.
Run sends four request vectors and the answers come out wrong. Fix prio_enc.sv. Grading uses three hidden checks.
Write and run your answer in the browser. The hidden tests check it, and it’s free.