Finding Digits in Base 10 Representation of Input Number Converted from Base

199 Views Asked by At

I would like to know the function for finding the number of digits in a base 10 number when converted from a number in another base.

For example, if I have the input number, 10010 and and input base, 2, then I need this function to output 2, the number of digits in 18, which is the number converted from base 2 to base 10.

I know that the number of digits in a base 10 number is just $log_{10}number + 1$, but I need a function which also incorporates the base for the input number.

1

There are 1 best solutions below

4
On

The number of digits in the base $b$ representation of $n$ is $\lfloor \log_b(n) \rfloor + 1$.

EDIT: If you prefer base-$10$ or natural logarithms, $$\log_b(n) = \dfrac{\log_{10}(n)}{\log_{10}(b)} = \dfrac{\ln(n)}{\ln(b)} $$