The largest number that can be represented by an n digit number in base b is bn - 1. Hence, the largest number that can be represented in N binary digits is 2N - 1. We need the smallest integer N such that:
2N - 1 = bn - 1
? 2N = bn
Taking the base 2 logarithm of both sides of the last expression gives:
log2 2N = log2 bn
? N = log2 bn
? N = log bn / log 2
Since we want the smallest integer N that satisfies the last relation, to find N, find log bn / log 2 and take the ceiling.
In the last expression, any base is fine for the logarithms, so long as both bases are the same. It is convenient here, since we are interested in the case where b = 10, to use base 10 logarithms taking advantage of log1010n == n.
For n = 3:
N = ?3 / log10 2? = 10
For n = 4:
N = ?4 / log10 2? = 14
For n = 6:
N = ?6 / log10 2? = 20
And in general, for n decimal digits:
N = ?n / log10 2?