There are 256 8-bit numbers: 00000000 to 11111111 (decimal 0 to 255).
- A quarter of these begin with 10, so the probability of randomly selecting a binary number in the range 128-191 (binary 10000000 to 10111111–64 numbers) is ¼ or 0.25.
- The number of binary numbers containing 4 zeroes is 8C4=70, the number of ways of selecting or deselecting 4 different powers of 2 out of 8 possible. So the probability is 70/256=35/128.
The probability of 1 or 2 is the sum of these probabilities less any numbers containing 4 zeroes and beginning with 10 (i.e., between 128 and 191 and in the set {135 139 141 142 147 149 150 153 154 156 163 165 166 169 170 172 177 178 180 184}, which are the 20 numbers containing 4 zeroes). So the probability is (64+70-20)/256=114/256=57/128.
It’s not quite clear what the last part means, but we can assign a probability to every 8-bit binary number. Given the probability of a zero in any particular position i, we can calculate the probability of 1 in the same position=1-½ꜞ. The probability associated with each number is (1-2¹⁻ꜞ)aꜟ+2⁻ꜞwhere aꜟis 0 or 1. The combined probability for the entire number is the product of the individual probabilities: ∏(1-2¹⁻ꜞ)aꜟ+2⁻ꜞ. For example, the probability associated with 00001111 would be:
(1/2)(1/4)(1/8)(1/16)(31/32)(63/64)(127/128)(255/256)=63247905/2³⁶.
For 150₁₀=10010110₂ it’s:
(1/2)(1/4)(1/8)(15/16)(1/32)(63/64)(127/128)(1/256)=120015/2³⁶.
2³⁶=68719476736.
If this exercise is repeated for each of the 114 numbers, the products can be summed to give the overall probability of selecting a binary number meeting the given requirements. When this is done the probability comes to about 0.12748.