TITLE: How to change from base $n$ to $m$
QUESTION [11 upvotes]: Does anyone know of an algorithm or formula for converting between and arbitrary base $n$ to another base $m$?

REPLY [4 votes]: One sraightforward way it to write the number in (nested) Horner polynomial form then do the base conversion as an "evaluation" into the target radix, e.g. let's convert $397$ from radix $10$ into radix $\color{#c00}9,\,$ where $\rm\color{#c00}{red}$ numbers are in radix $\color{#c00}9$
$$\begin{align} 397 
\,&=\, (3\cdot 10\, +\, 9)\,10 +7\\
&=\, (\color{#c00}{3\cdot 11+10})10+7,\ \ {\rm by}\ \ 10_{10} = \color{#c00}{11}_9,\ 9_{10} = \color{#c00}{10}_9\\
&=\qquad\quad\ \  \color{#c00}{43\cdot 11}+7\\
&=\qquad\qquad\ \ \ \color{#c00}{473}+7\\
&=\qquad\qquad\ \ \ \color{#c00}{481}\end{align}$$
This yields an obvious recursive algorithm: for a digit list $\rm\: [d_0,d_1,\cdots,d_k]\:$ denoting $\rm\: d_0 + n\:(d_1 + n\:(d_2 + \cdots + d_k))\:$ in radix $\rm\:n,\,$ recursively compute the radix $\rm\:m\:$ representation of the tail $\rm\:[d_1,d_2,\cdots,d_k],\:$ then, employing radix $\rm\:m\:$ operations, multiply it by $\rm\:n\:$ then add $\rm\:d_0,\:$ after converting both to radix $\rm\:m\:.\:$ Said more succinctly
$$\rm [d_0,d_1,\cdots,d_k]^{(n\ \mapsto\ m)}\ =\:\ d_0^{(n\ \mapsto\ m)}\ +\ n^{(n\ \mapsto\ m)}\ *\ [d_1,d_2,\cdots, d_k]^{(n\ \mapsto\ m)}$$
Unwinding this recursion, it amounts to applying the conversion operation $\rm\:(\ \ )^{\ (n\ \mapsto\ m)}\:$ to all terms in the fully expanded Horner form given above. Note that this conversion map commutes with $+$ and $*$ because it is a ring isomorphism from the integers represented in radix $\rm\:n\:$ to the integers represented in radix $\rm\:m\:$. One is essentially using this isomorphism to transport structure between the rings - here the structure being the polynomial form that is implicit in radix representation.
Various optimizations are possible. For example, for fixed $\rm\:n > m\:$ one can precompute a table mapping the digits in radix $\rm\:n\:$ to their radix $\rm\:m\:$ conversions. Note also that if $\rm\: m = n^k\:$ then the conversion is trivially achieved by partitioning into chunks of $\rm\:k\:$ digits.