In computer code (i.e. python) I want to express the digits of pi
.1415926...
in a different base. So I want to find the coefficients $a_n$ of the series
$$.1415926... = \sum_n a_n q^{-n}$$
with the base q.
I know how to do that for a finite digit number, but in the end I want to read just a bunch of digits from a file (containing possibly thousand of digits) and do the conversation in the code.
I tried to do that in base 50 so that $50^{-1}=0.02$. So as the first digit of pi is 0.14, the 0.02 fits in it 7 times. So the first digit in base 50 is "7". Then the next term is 0.0004 which also works, but when moving on the terms becomes longer and longer (i.e. like 0.000...0065536), and be impractical again when trying to convert thousands of digits.
So for a number with thousands or million of digits mathematically this can be done easily, but in a programatically way that is not feasible.
So ideally I read the first few digits, find the first number in the new base, then I read the next digit of the number, find the next number in the new base and so on. Without reading/manipulating the whole million digits I might want to convert ...
(Too long for a comment.)
The following assumes that you want to output exact digits, not significant digits - difference being that, for example, the first $4$ exact decimal digits of $.1415926$ are $.141\color{red}5$, but $.1415926$ to $4$ significant digits is $.141\color{red}{6}$. It also assumes the implementation has no arithmetic limits on the size and precision involved.
In general, it is not possible to avoid reading the whole input number before determining the very first output digit. For example, suppose the target base is $7$ and the input number is $0.57142857$. Then the first base-$7$ output digit is $\lfloor 7 \cdot 0.57142857\rfloor =3$. But $\lfloor 7 \cdot 0.5714285\color{red}{8}\rfloor = \color{red}{4}$, so until you read the last input digit and check whether it's $\le 7$ vs. $\ge 8$ you can't tell if the first base-$7$ digit of the output is $3$ vs. $4$.
[ EDIT ] $\;$ This is a worked out example with target base $7$ and input number $x = 0.57142857$.
After reading the first decimal digit $5$ we know that $0.5 \le x \lt 0.5\overline{9} = 0.6$. The first base-$7$ digit of $x$ is $\lfloor 7 \cdot x \rfloor$. However, the range we know $x \in [0.5, 0.6)$ is not enough to determine the first base-$7$ digit, because the two ends of the interval give different results $\lfloor 7 \cdot 0.5 \rfloor = 3 \ne 4 = \lfloor 7 \cdot 0.6 \rfloor$. This means we need to read the next decimal digit, which is $7$. This narrows down the range to $x \in [0.57, 0.58)$ but again the two ends of the interval give different results for the first base-$7$ digit $\lfloor 7 \cdot 0.57 \rfloor = 3 \ne 4 = \lfloor 7 \cdot 0.58 \rfloor$ which means we need to read yet another digit, and repeat until the range narrows down enough to identify a unique base-$7$ digit. In the case of $x = 0.57142857$, this requires reading all the digits to the end.
$$ \begin{matrix} 3.5 &= 7 \cdot 0.500000000 &\le 7 \cdot 0.5xxxxxxx &\lt 7 \cdot 0.600000000 &= 4.2 \\ 3.99 &= 7 \cdot 0.570000000 &\le 7 \cdot 0.57xxxxxx &\lt 7 \cdot 0.580000000 &= 4.06 \\ 3.997 &= 7 \cdot 0.571000000 &\le 7 \cdot 0.571xxxxx &\lt 7 \cdot 0.572000000 &= 4.004 \\ 3.9998 &= 7 \cdot 0.571400000 &\le 7 \cdot 0.5714xxxx &\lt 7 \cdot 0.571500000 &= 4.0005 \\ 3.99994 &= 7 \cdot 0.571420000 &\le 7 \cdot 0.57142xxx &\lt 7 \cdot 0.571430000 &= 4.00001 \\ 3.999996 &= 7 \cdot 0.571428000 &\le 7 \cdot 0.571428xx &\lt 7 \cdot 0.571429000 &= 4.000003 \\ 3.9999995 &= 7 \cdot 0.571428500 &\le 7 \cdot 0.5714285x &\lt 7 \cdot 0.571428600 &= 4.0000002 \\ 3.99999999 &= 7 \cdot 0.571428570 &= 7 \cdot 0.57142857 &\color{lightgray}{\lt 7 \cdot 0.571428580} &\color{lightgray}{= 4.00000006} \end{matrix} $$
Once we reached the end, we determined that the first digit in base-$7$ of $0.57142857$ is $3$. Note, however, the grayed out part on the last line, which means that if the input number had more digits $x = 0.57142857\ldots$ we would still need to read more of them to determine the first base-$7$ digit.
Compare that to $x = 0.57142858$, where the last line would read, instead:
$$ \begin{matrix} \color{red}{4}.00000006 &= 7 \cdot 0.571428580 &\le 7 \cdot 0.57142858\ldots &\lt 7 \cdot 0.571428590 &= \color{red}{4}.00000013 \end{matrix} $$
This shows that the first base-$7$ digit of all numbers $0.57142858\ldots$ would be $4$.