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.


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)} $$

  • $\begingroup$ The output of this is the number of digits if I am converting from base 10 to base $b$, not from base $b$ to base 10. I need an input base and then the output of the digits in the base 10 representation. $\endgroup$ – user387135 Nov 8 '16 at 1:10
  • 1
    $\begingroup$ I think what the OP asked for is the function that, for base $b$ and its representation $r$, returns the number of digits in its base $10$ equivalent number $n$. I don't think floor functions of logs would be useful since, for example, they hide the difference between $1000000_2 (= 64)$ and $1111111_2 (= 127)$, which are supposed to return $2$ and $3$ respectively, whereas the floor function would make them both give $2$. $\endgroup$ – 2012ssohn Nov 8 '16 at 1:12
  • $\begingroup$ @2012ssohn is correct. This is the problem I am facing. $\endgroup$ – user387135 Nov 8 '16 at 1:24
  • $\begingroup$ Robert Israel's answer is definitely correct if you allow the answer to be written as $\lfloor \log_b(n_b)\rfloor$. However, this isn't going to work if you throw it into a calculator... you're first going to need to convert $n$ to base $10$. This is the major flaw. $\endgroup$ – Brevan Ellefsen Nov 8 '16 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy