I finally came up with the circuit that converts 16-bit number into its size (i.e. finding how many bits is the number without leading zeroes).

It has 3 stages:

- first -- make all bits after the most significant "one" bit to be also "one" bits ( like 0001 0110 => 0001 1111 ), using OR gates;

- second -- find an edge with XOR gates -- this turns the 0001 1111 number into 0001 0000;

- third -- encode result from second stage into the final magnitude value ( 0001 0000 => 0000 0101, i.e. there are 5 bits in number );

Here is the schematic:

One significant drawback here is the long ripple through OR gates, which makes all action up to 18 gate delays long, which is likely one of the longest paths in ALU circuit. This is subject for further investigation right now. Maybe there is a way to make this go faster with fancier wiring.

As for the time being, I am thinking and trying to evaluate, if this circuit is needed at all. It can be most useful in division routine, and maybe also in floating point routines, but I am not seeing this as frequently used feature. All it does can be done with other ALU parts, in several operations.

## Discussions

## Become a Hackaday.io Member

Create an account to leave a comment. Already have an account? Log In.