# How many bytes contain exactly two 1's?

I know that the answer is C(8,2), but I don't get, why. Can anyone, please, explain it?

-

## migrated from stackoverflow.comJan 25 '11 at 12:22

This question came from our site for professional and enthusiast programmers.

$C(m,n)$ is usually notated $\binom{m}{n}$ (binomial coefficient) – Raphael Jan 25 '11 at 13:34

C(8, 2) means "8 choose 2", which in this case should be interpreted as "how many ways can you choose 2 items out of 8 possible". Here the 8 items are the bits, and the 2 comes from the bits you "select to be 1". That is, there are just as many bytes with exactly two 1s as there are ways to select 2 bits from 8 possible.

-
Got it!!! Thank you! The problem is that i read the task as "how many bytes are in two 1's". ps: I am not a native English-speaker. ) – Nika Jan 22 '11 at 20:35

C(8,2) is kinda self explanatory:
you have 8 bits, and each time you choose 2 of them to be ones.

-
en.wikipedia.org/wiki/Combination seems pretty straightforward to me. – Paul Nathan Jan 21 '11 at 23:43

$C[8, 2] = 8!/((8-2)!2!) = (8!/6!)/2! = (8*7)/2 = 28$. Think of it this way. The 8 is the choice of the first bit, and the 7 is the choice of the second bit (it's only 7 because there are only 7 bits available after the first bit is decided). The 2 represents the number of permutations of the chosen bits. We divide by 2 because we don't want to count each ordering of the chosen bits separatetly.

-