Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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.

share|cite|improve this question
Please check my question… – Mathlover Jan 25 '13 at 6:47
up vote 6 down vote accepted

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

share|cite|improve this answer

An alternative:

$f(n)={\large\lfloor} 10\cdot\left(10^{-n}\cdot x-\lfloor 10^{-n}\cdot x\rfloor \right){\large\rfloor}$.

share|cite|improve this answer
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
My bad you are correct, the function I listed corresponds to the nth power of 10, it should be the new one you listed, where you scaled x by a factor of 10. – Ethan Jan 25 '13 at 7:30
@Ethan: Just thought I'd double check that detail, but the idea is clear and gives another, maybe better way to think of it. Thanks again. – Jonas Meyer Jan 25 '13 at 7:32
Just a remark: I arrived at my form essentially by thinking of clearing the digits to the left first, then those to the right. Similarly, Ethan's form can be thought of as clearing the digits to the right first, then those to the left. – Jonas Meyer Jan 25 '13 at 17:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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