Number of powers of $2$ having leading digit $1$

How many of the numbers $2^m$ (where $0\le m\le M)$ have leading digit $1$?

My trial -

Since leading digit $=1$, whenever $2^m$ reaches or just crosses a $10^x$ and is less than $2 \cdot 10 ^ x$, that $m$ is eligible i.e.

$$10^x \le 2^m \lt 2\cdot 10^x.$$

But $x$ also depends on the current $m$, so $x$ must also satisfy

$$(m-1)\cdot \log 2 \le x \lt m \cdot \log 2$$ (which directly follows from the previous inequality).

So the final summation is:

$$\sum\limits_{(x, m)}\left([10^x \le 2^m \lt 2\cdot 10^x]\cdot[(m-1)\log 2 \le x \lt m \log 2]\cdot[0 \le m \le M]\right).$$

I think I am making it a bit too complex, my main confusion is regarding the manipulation of $x$, can anyone help? (The brackets are Iverson notation which is $1$ if true and $0$ if false).

-
Sure you are making it too complex, your first two conditions are the same. And just sum over one index, not two. – vonbrand Jan 24 '13 at 0:22

If $2^m$ starts with a $1$ then $2^{m-1}$ and $2^{m+1}$ do not. And if $2^m$ has one more decimal digit than $2^{m-1}$ then it must start with a $1$.
So all you need to know is how many powers of $10$ are less than or equal to $2^M$. This is $$\lfloor 1+ \log_{10} 2^M \rfloor = 1+\lfloor M\log_{10} 2\rfloor$$ where you need to add $1$ to deal with $2^0=1$. For $M \gt 0$ you could instead write $\lceil M\log_{10} 2\rceil$.