This is probably a very basic question but nonetheless I choked when I got in a math for programmers class. I was taught how to convert from base to base but I have no idea how to convert fractions to decimals in bases other than base 10.
-
I appreciate all the feedback. However, I am still a bit confused it seems I need to refresh my math skills. Gathering all the information provided by all you awesome users, I think the answer to the question is an infinite 0.111111111.... – Squanchinator Jul 30 '14 at 06:04
4 Answers
Hint: Using the formula for the sum of an infinite geometric series, we have: $\dfrac{1}{7} = \dfrac{1}{8-1} = \dfrac{\tfrac{1}{8}}{1-\tfrac{1}{8}} = \dfrac{1}{8}+\dfrac{1}{8^2}+\dfrac{1}{8^3}+\dfrac{1}{8^4}+\cdots$
- 54,331
Jimmy K4542 gives a fine answer for the specific case, but suppose you wanted $1/37$ in base $8$? Remember that the first place after the point is $\frac 18$, the second is $\frac 1{8^2}$, the next $\frac 1{8^3}$ and so on. Multiply $\frac 1{37}$ by $8$ and take the integer part, which is zero. There is therefore a zero in the eighths place. Multiply again by $8$, getting $\frac {64}{37}$ and take the integer part, which is $1$. The value in the sixty-fourths place is a $1$. Take the fractional part, which is $\frac {64-37}{37}=\frac {27}{37}$, multiply by $8$, getting $\frac {216}{37}$, take the integer part, which is $5$, which is the next place. Then what remains is $\frac {31}{37}$ and on you go.
- 374,822
I would emphasize that, in base eight, $$ 1 = 0.77777777777777777777777777777... $$ on forever, so $$ 1/7 = 0.11111111111111111111111111111... $$
- 139,541
-
21=0.77777777...? That's crazy. Next you'll be telling me 1=0.99999999... – abnry Jul 28 '14 at 02:41
-
Working in base $B$, we want to find the radix representation of a fraction $\frac{a}{b} $, and we're given that $0 < \frac{a}{b} < 1$.
$$\begin{align} \frac{a}{b} & = 0.d_1d_2d_3d_4\dots\\ \frac{Ba}{b} & = d_1.d_2d_3d_4\dots\\ \left\lfloor\frac{Ba}{b}\right\rfloor & = d_1\\ \frac{Ba}{b} - d_1 & = 0.d_2d_3d_4\dots\\ \frac{Ba - d_1b}{b} & = 0.d_2d_3d_4\dots\\ \end{align}$$
And now we have another fraction between $0$ and $1$ and we can find out the next digit in the same way.
- 4,216
- 15
- 23