About Computer Science…test
This page is under construction.
This page is a test.
Binary Numbers
How to count the number of ones in a binary number
A number like
13 is
1101 in binary. The sum of the
binary digits is three. This is easy enough to see. Can we compute
this without first converting a number from decimal to binary? Yes!
One technique is based on dividing by two and rounding down.
13 divided by two is
6.5, which rounded down is
6.
Next we get
3, then
1, then
0.
We can turn this into one long substraction
136310,
which is 3. This is the number of ones in the binary representation
of 13
(1101).
