# selecting an arbitary digit from an integer

Let us say I have an integer of an arbitrary length such as:

$209484250490600018105614048117055336$

Is there an elegant function which allows me to select the $n$-th digit such that:

$f(1) = 6$ $f(2) = 3$ and so forth.

-
Please check my question math.stackexchange.com/questions/141919/… –  Mathlover Jan 25 '13 at 6:47

Yes, it can be expressed concisely as $f(n) = \lfloor x \cdot 10^{-n+1} \rfloor \mod{10}$

-
$f(n)={\large\lfloor} 10\cdot\left(10^{-n}\cdot x-\lfloor 10^{-n}\cdot x\rfloor \right){\large\rfloor}$.
Iterated floor functions can be simplified, $$f(n)=\lfloor 10^{-n}\cdot x{\large\rfloor}-10\lfloor 10^{-(n+1)}\cdot x{\large\rfloor}$$ –  Ethan Jan 25 '13 at 7:14
@Ethan: Thank you. Are you sure it isn't $f(n)=\lfloor 10^{-n+1}\cdot x{\large\rfloor}-10\lfloor 10^{-n}\cdot x{\large\rfloor}$? (Although it would make sense if $f(n)$ corresponded to the coefficient of $10^n$ rather than $10^{n-1}$, I'm using the convention in the question.) –  Jonas Meyer Jan 25 '13 at 7:22