Geometry Solver
Home › Counting and number theory

Count the ones in a binary sum of powers of two

Each distinct power of two marks one bit

The binary form of is a one followed by zeros. A sum of different powers of two has a one at each listed exponent. Repeated exponents require carrying before you count bits.

Problem

How many ones appear in the binary representation of ? Also check the smaller example .

Answer

The large expression has ones; has ones.
Both counts follow from distinct exponent positions, without expanding the integers.

Step-by-step solution

1. Rewrite everything as powers of two

The full expression is .

2. Read the bit positions

The three exponents , and are distinct, so there is a one in each of those binary positions and zero elsewhere. No carrying is needed. Thus the count is .

3. Check a smaller example

has a one in positions and , giving ones.

Add to Chrome - solve your own

Screenshot any problem on your screen and get the steps. Chrome on a computer; free.