# Given a number, how to find the length of its binary representation?

I think of $\text{log}_2$. But it does not work. For $8 = 2^3$, but the binary representation of 8 is $1000$. The length of it is 4. Any suggestion or help? Thanks.

• Suggestion: continue thinking of $\log_2$, but don't give up on it at the first sign of failure. Just needs a tiny adjustment. – Erick Wong Nov 2 '15 at 5:25

The length of $$x$$ is $$\lfloor{(\log_2(x))}\rfloor+1$$.

For numbers $$\leq64$$ the length of $$x$$ is $$\lfloor\log_2(x)\rfloor + 1$$. After $$64$$ and $$x\equiv 1\;\text{mod}\; 2$$, the length is $$\lfloor\log_2(x)\rfloor +$$.

if(x > 64 && x % 2 != 0){