The number of bits needed to represent n in binary is ⌊log2(n)⌋+1. For example, n=8=10002 needs 4 bits, and log2(8)=3.
Why? Because 2k−1≤n<2k, so k−1≤log2(n)<k, giving k=⌊log2(n)⌋+1. This is why 32-bit integers can hold values up to 232−1.
Bit manipulation algorithms often run in O(logn) time because they process one bit per step, and there are O(logn) bits.