How many 8-bit binary numbers have a 1 as the first bit, or third bit, or both?

898 Views Asked by At

I tried doing C(8,1) for when 1 is the first bit, and third bit, and C(8,2) when it's both and multiplying them but I didn't get the right answer.

2

There are 2 best solutions below

2
On

$C(8,1)$ is the number of 8-bit binary numbers with exactly one 1, and $C(8,2)$ is the number of binary numbers with exactly two $1$'s. I don't think that's what you want to count.

Hint: How would you most easily describe a number which doesn't fulfill that criterion? How many such numbers are there? And how many 8-bit binary numbers are there in total?

7
On

There are total $2^8$=256 8 bit binary numbers.
You want those having 1 at $1^{st}$ or $3^{rd}$ bit.
So, go for those who do not have; i.e. numbers having 0 at their $1^{st}$ and $3^{rd}$ bit

Fix them as 0, and fill remaining 6 bits in either of 0 and 1
There are $$2\cdot2\cdot2\cdot2\cdot2\cdot2=2^6=64$$ 64 numbers do not have 1 at $1^{st}$ and $3^{rd}$ bit.
So, total-not having 1= those having 1

$$256-64=192$$ is your answer

You can also go for counting individually numbers having 1 at $1^{st}$ (0 at $3^{rd}$), 1 at $3^{rd}$ bit (0 at $1^{st}$), and 1 at both $1^{st}$ and $3^{rd}$ bit, and adding all. (Try!)