Home › Practice › RTL Design › Count the leading zeros
Count the leading zeros
EasyRTLcombinationalarchitecture
A calculator that works with very large and very small numbers must keep every number in a standard shape. After a subtraction the result may start with many zeros, and it has to find out how many.
Concept first. Floating-point numbers are stored normalised: the digits are shifted until the first digit is a 1, and the exponent is adjusted by the size of the shift. After a subtraction the result can have many zeros at the front, so the hardware needs to know how far to shift. A leading-zero counter reports how many zeros come before the first 1. Examples for 8 bits: 10110000 has 0 leading zeros, 00010100 has 3, and 00000001 has 7. When the whole number is zero there is no 1 at all, and the answer is 8. Counting is done with logic that looks at the bits from the top, not with an adder.
What to build.
lzc8(x):xis 8 bits.- Output
n[3:0]is the number of zeros before the first 1, counting from the top bit (bit 7). It is 8 whenxis 0. - No clock.
- Rule: no
+,-,*,<or>. Use logic only.
No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.