= Bit length
{title2=$\ell(n)=\lfloor\log_2 n\rfloor+1$}
For a <positive integer> $n$, its bit length is the number of <binary digits> in its usual representation:
$$
\ell(n)=\lfloor\log_2n\rfloor+1.
$$
Equivalently, $\ell(n)$ is the unique <positive integer> satisfying $2^{\ell(n)-1}\leq n<2^{\ell(n)}$. For example, $13=1101_2$ has bit length four, and $8=1000_2$ has bit length four too. The inequalities provide an exact characterization without a floating-point <logarithm>.
Many <integer> programming interfaces define the bit length of zero as zero. That convention counts no significant one-bit; it differs from the written <binary> <numeral> $0$, which has one character. A fixed-width <machine word> can also contain leading zero <bits> that do not contribute to the value's bit length.
Back to article page