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.
|
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. |
|||||
|
|
Yes, it can be expressed concisely as $f(n) = \lfloor x \cdot 10^{-n+1} \rfloor \mod{10}$ |
|||
|
|
|
An alternative: $f(n)={\large\lfloor} 10\cdot\left(10^{-n}\cdot x-\lfloor 10^{-n}\cdot x\rfloor \right){\large\rfloor}$. |
|||||||||||||
|