1

I need an equation that can be easily changed to output the digit which is held in the 1's slot, 10's slot, 100's slot, etc.

EX. I want the 100's digit in 6810 EX2. I want the 1's digit in 29115

What the equation should do is that once it is done calculating, all that is left is the selected "slot" or whatever it is called, nothing else, no other numbers, just the number in the slot I wanted

It would help if the equation was really simple, but anything helps

  • these are all great answers.... but.... is this possible with only simple algebra? Like only adding, subtracting, multiplying and dividing? No exponents/functions/mods – CocoaMix86 Sep 03 '14 at 15:04
  • It can be done with the basic operations: $10^k = \underbrace{10 \cdot \cdots \cdot 10}_{k \times}$, modulo operation can be done by applying division, multiplication and subtraction. Only the rounding down (floor function) is needed as well. And then one would talk about how your basic operations are implemented - on the integers or fixed point or floating point. – mvw Sep 03 '14 at 20:04

3 Answers3

1

If you want the $10^k$'s digit of $n$, you should compute $\left\lfloor\dfrac{n}{10^k}\right\rfloor \pmod{10}$.

Ex1: If you want the $100 = 10^2$ digit of $6810$, then $\left\lfloor\dfrac{6810}{10^2}\right\rfloor = \lfloor 68.1\rfloor = 68 \equiv \boxed{8} \pmod{10}$.

Ex2: If you want the $1 = 10^0$ digit of $29115$, then $\left\lfloor\dfrac{29115}{10^0}\right\rfloor = \lfloor 29115\rfloor = 29115 \equiv \boxed{5} \pmod{10}$.

JimmyK4542
  • 54,331
0

To get the one's digit of $x$: $$f(x)=((x\mod 10)-(x\mod 1))/1$$ To get the ten's digit of $x$: $$f(x)=((x\mod 100)-(x\mod 10))/10$$ To get the hundred's digit of $x$: $$f(x)=((x\mod 1000) - (x\mod 100))/100$$ and so on.

JRN
  • 6,566
0

Suppose you want the digit of the nonnegative integer $x$ corresponding to the power $10^n$ (so $n$ can be $0,1,2,\ldots$). This is just

$$\left\lfloor\frac{x}{10^n}\right\rfloor - 10\left\lfloor\frac{\left\lfloor\frac{x}{10^n}\right\rfloor}{10}\right\rfloor$$

MPW
  • 43,638