TAOCP 4.4 Exercise 2
Method 1a extends to mixed radices by repeated division with changing divisors.
Exercise 2. [**] [25] Generalize Method 1a so that it works with mixed-radix notations, as in exercise 1, and give an example of your generalization by manually solving the same conversion problem stated in exercise 1.
Verified: yes
Solve time: 1m15s
Method 1a extends to mixed radices by repeated division with changing divisors. Given
$N=a_m b_{m-1}\cdots b_0+\cdots+a_1b_0+a_0,$
the target digits are obtained from right to left by
$A_0=N\bmod B_0,\qquad N_1=\lfloor N/B_0\rfloor,$
$A_1=N_1\bmod B_1,\qquad N_2=\lfloor N_1/B_1\rfloor,$
and, in general,
$A_j=N_j\bmod B_j,\qquad N_{j+1}=\lfloor N_j/B_j\rfloor.$
The process stops when the final quotient is less than the next radix; that quotient is the leading digit.
For the example,
$N=3\cdot24\cdot60\cdot60+9\cdot60\cdot60+12\cdot60+37=292357.$
Successive mixed-radix divisions give
$A_0=292357\bmod16=5,\qquad N_1=18272,$
$A_1=18272\bmod14=2,\qquad N_2=1305,$
$A_2=1305\bmod8=1,\qquad N_3=163,$
$A_3=163\bmod20=3,\qquad N_4=8.$
Hence
$292357=8(20)(8)(14)(16)+3(8)(14)(16)+1(14)(16)+2(16)+5,$
so the mixed-radix representation is
$\boxed{8\text{ long tons},\ 3\text{ hundredweights},\ 1\text{ stone},\ 2\text{ pounds},\ 5\text{ ounces}.}$