# How to convert between base-10 and base-26?

I am trying to write a JAVA program that searches through pi to find a given string. However, I don't quite understand how you convert 3.141592...to D.DRSQLOLYR... (as seen on this site: here)? Could someone please carefully explain to me a simple algorithm for converting an irrational number such as pi into letters? Thanks!

-
Express pi as c x 26^0 + d x 26^-1 + e x 26^-2... – FiniteA Mar 15 '12 at 3:53
there are two parts to this problem. Firstly, you need to calculate pi to an arbitrary precision. Secondly, you need to convert to base 26. Which one gives you trouble? – Winston Ewert Mar 15 '12 at 3:55
Probably both...Does the arbitrary precision alter the output? e.g. if I calculate at x=101 instead of x=100 will I get different beginning values? – Mr_CryptoPrime Mar 15 '12 at 4:04

So $3 = D$, and that's that for the integer part.

Suppose I took the approximation .14159 for the fractional part, and I wanted to convert that to base 26. $.14159 \cdot 26 = 3.68134$. The integer part is $3$, so mark down another $D$.

Now $.68134 \cdot 26 = 17.71484$. The integer part is $17$, so we mark down $R$ and continue.

$.71484 \cdot 26 = 18.58584$. The integer part is $18$, so we mark down $S$.

So the beginning is $D.DRS$ - I didn't start with many decimals, so I will quickly lose precision now. To get better base 26 representations, you choose better decimal and or fractional representations.

You might ask, why does this work?

The idea is that we are looking at $.14159 = c_1 26^{-1} + c_2 26^{-2} + c_3 26^{-3} + ...$ And this looks awkward. But if we multiply by $26$, we get

$26 \cdot .14159 = c_1 + c_2 26^{-1} + \ldots$. So the integer part is the first coefficient, which is the first decimal digit. Then repeating gives the next ones. And this is very easy to automate, as it's essentially presented in algorithmic form.

-
OH, ok. I think I understand now? Thanks! :) – Mr_CryptoPrime Mar 15 '12 at 4:14