As a solution to this question, we can define a function $f_b(x, n)$ which finds the digit in the $n$th position of $x$ in base $b$.

$$ f_b(x, n) = \left\lfloor \frac{x}{b^n} \right\rfloor \bmod b $$

It even works for decimals, for example:

e = 2 . 7  1  8  2  8  1  8  2  8 ...
    0  -1 -2 -3 -4 -5 -6 -7 -8 -9 th position

$$ f_{10}(e, -8) = 2 \quad \checkmark $$

However, when using a non-integer base, all the digits are fractional.

$$ f_\pi(e, [0,-1,-2,\dots]) = [2, 1.717, 0.867, 2.319, \dots] $$

For reference, Wolfram Alpha states that $e$ in base $\pi$ is actually 2.2021201002111...

Additionally, for negative bases, all the digits of $f$ are negative. Wolfram Alpha states that $e$ in base $-10$ is 3.3223222325590...

Furthermore, the function also screws up if $x_b$ is negative. So I am also looking for a function to have a way of differentiating positive and negative numbers (especially important in negative bases, since for example, 21 in decimal would be -39 in negadecimal).

My question is if there is a function which does this but is also valid even for non-integer and negative bases. I'm sure there would be, but I don't know what we need to modify such that this would happen. In other words, is there a function such that

$$ f_b\left(\sum_{k=-\infty}^\infty a_k b^k, n \right) = a_n \qquad b\in\mathbb{R} $$


I have since then found a recursive method for non-integer but not negative bases :

Start by calculating $A=\lfloor\log_b n\rfloor$, then

$$ U_1 = f_b(n, A) = \left\lfloor\frac{n}{b^A}\right\rfloor $$ $$ U_2 = f_b(n, A-1) = \left\lfloor\frac{n-U_1b^A}{b^{A-1}}\right\rfloor $$ $$ U_3 = f_b(n, A-2) = \left\lfloor\frac{n-U_1b^A-U_2b^{A-1}}{b^{A-2}}\right\rfloor $$

etc. The simple problem with this one is when it deals with a negative base, it returns negative digits.

  • $\begingroup$ I think you are mistaken about the "digits" for such irregular bases. The digits are always nonnegative integers. For example, the statement "$e$ in base $\pi$ is $2.20212\ldots$" means $$e = 2 + 2\pi^{-1}+ 0\pi^{-2}+2\pi^{-3}+1\pi^{-4}+2\pi^{-5}+\cdots$$ and the statement "$e$ in base $-10$ is $3.32232\cdots$" means $$e = 3 + 3(-10)^{-1} + 2(-10)^{-2} + 2(-10)^{-3} + 3(-10)^{-4} + 2(-10)^{-5}+\cdots$$ $\endgroup$ – MPW Feb 27 '19 at 20:48
  • $\begingroup$ @MPW How would one write 15 in base -10? The easiest way is to write -25, right? I know, particularly in irrational bases, that there are loads of different ways to write the same number, but I don't know for a negative base whether for every number there exists a positive number representation... $\endgroup$ – Infiaria Feb 27 '19 at 20:52

Hint: for starters, try to extract $a$, $b$, $c$ from $ \ a \pi^2 + b\pi +c \ $ or, more generally, the digits from $$ a_1/\pi + a_2/\pi^2 + a_3/\pi^3 + a_4/\pi^4 + a_5/\pi^5 + \cdots $$ The traditional mod function is not enough, because $$ a\pi^2 + b\pi +c \pmod {\pi} = a \pi^2 +c \neq c $$ since $a\pi^2$ isn't an (integer!) multiple of $\pi$.

Edit: Instead of $\!\bmod{\!\! }$, the function $\bmod{\!\! _b}$ that yields $$ \bmod_b \,\! : \ (A_k b^k + \cdots + A_2 b^2 + A_1 b + A_0) \mapsto A_0 $$ for any nonnegative integers $A_j \leq |b|$, seems to do the trick. But I have no definite formula for now. $% \mod\!\!\!_b: \ (A_k b^k + \cdots + A_2 b^2 + A_1 b + A_0) \mapsto A_0 $

  • $\begingroup$ Yes, that's what the function would intend to do but for any base $b$ ($a_0 + a_1b + a_2b^2 + \cdots + a_{-1}b^{-1} + a_{-2}b^{-2} + \cdots$), not just $\pi$. Of course I can look at something like $20122.1_\pi$ and say, that's $2\pi^4 + 1\pi^2$ etc. I just want a function that does this for any number $x$. $\endgroup$ – Infiaria Feb 27 '19 at 21:38
  • $\begingroup$ Of course I used $\pi$ as an example only. I think it would be enough to use, (instead of mod function) the function $\!\mod\!\!\!_b$ that yields $$ \mod\!\!\!_b: \ (A_k b^k + \cdots + A_2 b^2 + A_1 b + A_0) \mapsto A_0 $$ where $A_j$ are integers. However, I don't know for now how to define it as a formula. $\endgroup$ – eudes Feb 27 '19 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.