Possible Duplicate:
Compute fast log base 2 ceiling
What is the fastest possible way to find out how many binary digits a particular integer has when it is converted from decimal to binary in C/C++?
Ex. 47(10) = 101111(2)
So 47 has 6 digits represented in binary.
The fastest solution that’s presented at my favorite collection of bit twiddling hacks is Find the log base 2 of an N-bit integer in O(lg(N)) operations with multiply and lookup. It requires 13 instructions to find the highest set bit in a number.