Algorithm for Log2 of integers in binary representation

148 Views Asked by At

Let $x = \sum_{i=0}^N a_i 2^i$ where $a_i$ takes the values of either $0$ or $1$. It is easy to find lower and upper bounds to the value of $\log_2(x)$ simply by finding the most significant bit. How can I find the exact value of $\log_2(x)$ using the values $a_i$?

I would like to have some closed form, possibly using summation. I am not interested in efficient calculation on hardware or mere approximations.