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.

  • valid is 1 when en is 1 and at least one bit of req is set.
  • idx is the number of the lowest set bit of req. It is 0 when no bit is set.
  • grant is one-hot: only the lowest set bit of req, or all zeros if en is 0.
  • W is 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.