8. Let set $S$ consist of all positive integers not exceeding $2^{40}$, and whose binary representation contains exactly two 1s. If a number is randomly selected from $S$, the probability that this number is divisible by 9 is $\qquad$ .
8. $\frac{133}{780}$.

It is easy to see that $S=\left\{2^{a}+2^{b} \mid 0 \leqslant a \leqslant 39,0 \leqslant b \leqslant 39, a \neq b\right\}$, then $|S|=\mathrm{C}_{40}^{2}=780$.
Without loss of generality, assume $a<b$. Note that $2^{a}+2^{b}=2^{b}\left(2^{b-a}+1\right)$, so $9 \mid 2^{a}+2^{b}$ if and only if $9 \mid 2^{b-a}+1$, which means $2^{b-a} \equiv 8(\bmod 9)$.

It is easy to see that $2^{b-a} \equiv 8(\bmod 9)$ if and only if there exists a positive integer $k$ such that $b-a=6 k-3$. For each positive integer $k, b-a=6 k-3$ implies $0 \leqslant a \leqslant 39-(6 k-3)$, so there are $40-(6 k-3)=43-6 k$ ordered integer pairs $(a, b)$ satisfying $b-a=6 k-3$. From $6 k-3 \leqslant 39$, we know $1 \leqslant k \leqslant 7$. Therefore, the number of multiples of 9 in $S$ is equal to
$$
\sum_{k=1}^{7}(43-6 k)=7 \times 43-\frac{6 \times 7 \times 8}{2}=133 .
$$

Thus, the probability that a number randomly selected from $S$ is divisible by 9 is $\frac{133}{780}$.