Some answers suggest using the logarithm of n.
Now guess what is the first thing your computer does if you try to calculate log n: It converts n from an integer to a floating point number, and from the exponent of the floating point number you get the number of bits immediately. So whatever time complexity there is, you have spent it already before even trying to calculate the logarithm. Just be converting the integer n to a floating point number.
You also don't need to calculate the logarithm, which is very time consuming, just look at the exponent field in the floating point representation.
Assuming you are given a 64 bit integer:
count = 1
if any bit in (n & 0xffff ffff 0000 0000) is set then count = 32 and n = (n >> 32), count = count + 32.
if any bit in (n & 0xffff 0000) is set then count = count + 16 and n = (n >> 16).
if any bit in (n & 0xff00) is set then count = count + 8 and n = (n >> 8).
if any bit in (n & 0xf0) is set then count = count + 4 and n = (n >> 4).
if any bit in (n & 0x0c) is set then count = count + 2 and n = (n >> 2).
if any bit in (n & 0x02) is set then count = count + 1.
For a number that is stored in 2^k bits, this takes O(k).