How many $1$s are in the first $1023$ binary numbers?

Assuming the "first" binary number is $1$ note that the first $1023$ binary numbers, plus $0$, are all the binary numbers you can write with exactly $10$ binary digits or bits (prepending $0$s to "short" numbers, as in $0000101010_2$). Between all of them, you then have $1024 \cdot 10=10240$ bits, and for symmetry reasons exactly half of those, $5120$, are $1$s.


Hint: For how many of those numbers will the one's bit be a $1$ (in other words: how many of those numbers are odd)? For how many of them will the two's bit be a $1$? For how many of them will the four's bit be a $1$? And so on. Also, it will probably be advantageous to include $0$ (and thus look at a collection of $1024$ binary numbers) to make the counting a bit easier. Or, if $0$ is already included, include $1023$ initially, then correct for it when you're done counting.


Any such number can be represented by a string of 10 0s and 1s. The number of such strings with $n$ ones is $10$ choose $n$. Thus, the number of ones which appear is $$ \sum_{n=0}^{10} n{10 \choose n}=5\cdot 2^{10}. $$

Tags:

Binary