 ideklaraz7xz

2022-03-24

Function to grab specific digits from a number?
Recently I’ve been thinking a lot about grabbing digits from numbers, for things like calculating multiplication persistence, i.e. turning $1234$ into a $1×2×2×3×4$. I’ve been able to come up with
$\left[\mathrm{log}x\right]+1$
to output the number of digits of the given number x, as well as
$⌊\frac{x}{{10}^{⌊\mathrm{log}x⌋-n+1}}⌋$
which outputs the first n digits of any number x. But that’s about as far as I’ve been able to think up. Is there any way to construct a function that retrieves the nth digit of a given number? Forgive me if my notation or comprehension is poor, I have no formal education in this field of maths. Theodore Davila

Step 1
If the digit you require is n places from the right (indexed from zero so the units place is at position 0, the tens place is at 1 and so forth), then the following function will return the n-th digit of the decimal integer x:
$f\left(x,n\right)=⌊\frac{x}{{10}^{n}}⌋\left(\mathrm{mod}10\right)$
Example: $f\left(123456,3\right)=3$
You can replace 10 everywhere in the formula with any base b to generalise it.

Do you have a similar question?