Count number of logic 1's in 7 bit number

Georacer

Joined Nov 25, 2009
5,182
Since you will be using adders, try to see the operation as a sum of numbers. You have 7 numbers, the figures of your 7-bit number. All 7 numbers are 1-bit long. Let's name the figures of your number b0-b6, from the LSB to the MSB. Let's break down the operation:

Using a 1-bit Full Adder you can add 3 1-bit numbers (1st summand, 2nd summand, Carry-in) and get a 2-bit number.
Thus you can sum b0,b1,b2 with one FA, and b3,b4,b5 with a second FA.

You now have 2 2-bit numbers and one 1-bit number, the b6.

Using a 2-bit FA (which is made of 2 1-bit FA), you can add 2 2-bit numbers and 1 1-bit number (the carry in). You already have the 2 2-bit numbers as the result of the 2 previous additions, and the b6 will be used as the carry-in.
In the end, you end up wit 1 3-bit number, which can have a maximum value of 7.

In that implementation we used 4 Full Adders.

Is that clear?
 
Top