(01-26-2017 06:57 PM)Han Wrote: Here's the math for this specific example. A general program is left as an exercise for the diligent reader.

3.142 = 3 + 0.142

Convert the whole number part into base 7. Since it is only 3, then we are done. This leaves 0.142 for conversion to \( 0.d_1 d_2 d_3 \dotsm \) where the \( d_i \) are 0 through 6. Note that if we multiply the fractional part by 7 then we will get a value that is non-negative and strictly less than 7.

\[

\begin{align*}

0.142 & = 0.d_1 d_2 d_3 \dotsm \\

7\cdot 0.142 & = d_1 + 0.d_2 d_3 d_4 \dotsm\\

0.994 & = d_1 + 0.d_2 d_3 d_4 \dotsm \\

\end{align*}

\]

Therefore \( d_1 = 0 \). Now repeat...

\[

\begin{align*}

0.994 & = 0. d_2 d_3 d_4 \dotsm \\

7\cdot 0.994 & = d_2 + 0.d_3 d_4 d_5 \dotsm\\

6.958 & = d_2 + 0.d_3 d_4 d_5 \dotsm \\

\end{align*}

\]

Therefore \( d_2 = 6 \). Rinse and repeat (subtract the integer part and repeat for the fractional part) for as many digits as you need.

Nice and efficient math, Han!