How to algebraically represent digits of a number?

104 Views Asked by At

I need, in proper and widely accepted mathematical form, to algebraically represent each of all the digits in any given integer. Here is my mathematically illiterate way of conveying this idea to you: $$a_{1}a_{2}\dots a_{n-1}a_{n}\quad\text{where}\quad a_{1}\quad\text{would match first digit of given integer,}\quad a_{2}\quad\text{would match second, and so on}$$

Any help appreciated.

2

There are 2 best solutions below

3
On BEST ANSWER

The $k^{th}$ digit from the right (origin $0$) is

$$\left\lfloor\frac{n}{10^k}\right\rfloor\bmod 10.$$

E.g., $n=20519$, $k=2$,

$$\frac{20519}{10^2}=205.19,\\\left\lfloor205.19\right\rfloor=205,\\205\bmod10=5.$$

The number of digits is

$$\left\lfloor\log_{10}n\right\rfloor+1.$$


Note the $k$ can very well be negative.

1
On

It's better to number starting from the end, so your number is $$ x = \overline{ a_n a_{n-1} \ldots a_0} = \sum_{k=0}^n a_k 10^k$$ where $$ \lfloor x/10^k \rfloor \equiv a_k \mod 10 $$ This is, of course, for positive integers.