Function to grab specific digits from a number? Recently

ideklaraz7xz

ideklaraz7xz

Answered question

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
[logx]+1
to output the number of digits of the given number x, as well as
x10logxn+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.

Answer & Explanation

Theodore Davila

Theodore Davila

Beginner2022-03-25Added 14 answers

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(x,n)=x10n(mod10)
Example: f(123456,3)=3
You can replace 10 everywhere in the formula with any base b to generalise it.

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?