5. Leading zero count
Count the zeros at the top of an 8-bit value, before the first 1 when reading from bit 7 down.
lz is that count. When d is all zeros, lz is 8. There is no clock and no reset.
Ports
| Port | Dir | Bits | What it is |
|---|---|---|---|
d | in | 8 | The value to inspect. |
lz | out | 4 | Number of leading zeros, 0 to 8. |
Example
d = 0001_0110: three zeros come before the first 1, so lz = 3. d = 1000_0000 gives lz = 0; d = 0000_0001 gives lz = 7.
Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
Loading the editor…
Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.
Press Build to check your code with Yosys. Errors and warnings show here, and a clean build draws the logic diagram.
Press Build to see your design as logic blocks you can drive by hand.
Build your design to drive it by hand and see its signals here.