How to determine the number of digits needed to represent a number in different bases?
Yes, there is a way: $$f(n, \text{base}) = \log_{\text{base}} (n) + 1\text{.}$$
After you compute the value of $f(n,b)$, you have to use floor function to get the right integer value.
Explanation:
- for numbers $b^k$, you need $k + 1$ places ($100\dots...0$)
- for numbers $b^k -1$, you need $k$ places ($11\dots...1$)
- for numbers $n$ and $m$, such that $n\geq m$, then the number of places for $n$ is greater or equal to the number of places for $m$.
Hence, for all $b^{k - 1} \leq n \leq b^{k}-1$, you need $k$ places. The formula is just a fancy way to say this.