How to reverse digits of an integer mathematically? Is there a mathematical way to reverse digits of an integer mathematically? for example:
 $18539 \rightarrow 93581$
Let $n = \lfloor \log_{10}x\rfloor$, then $x$ has $n + 1$ digits. 

Let $x = \displaystyle\sum_{i=0}^nx_i10^i$ where $x_i \in \{0, 1, \dots, 9\}$. To obtain $x_k$ (i.e. the $(k+1)^{\text{st}}$ digit of $x$), first divide by $10^k$ to obtain 

$$x10^{-k} = \sum_{i=0}^nx_i10^{i-k} = \sum_{i=0}^{k-1}x_i10^{i-k} + \sum_{i=k}^nx_i10^{i-k}.$$

Note that the first sum on the right hand side is a non-negative number less than $1$ and the second sum is an integer. Therefore

$$\lfloor x10^{-k}\rfloor = \left\lfloor\sum_{i=0}^nx_i10^{i-k}\right\rfloor = \sum_{i=k}^nx_i10^{i-k}.$$

Now consider the corresponding expression for $k+1$:

\begin{align*}
\lfloor x10^{-(k+1)}\rfloor &amp;= \left\lfloor\sum_{i=0}^nx_i10^{i-(k+1)}\right\rfloor\\ 
&amp;= \sum_{i=k+1}^nx_i10^{i-(k+1)}\\ 
&amp;= 10^{-1} \sum_{i=k+1}^nx_i10^{i-k}\\ 
&amp;= 10^{-1}\left(\sum_{i=k}^nx_i10^{i-k}-x_k\right)\\ 
&amp;= 10^{-1}\left(\lfloor x10^{-k}\rfloor - x_k\right).
\end{align*}

Rearranging for $x_k$ we find $x_k = \lfloor x10^{-k}\rfloor - 10\lfloor x10^{-(k+1)}\rfloor$. Therefore, the number you are after is 

\begin{align*}
\sum_{k=0}^nx_{n-k}10^k &amp;= \sum_{k=0}^n\left(\lfloor x10^{-(n-k)}\rfloor - 10\lfloor x10^{-(n-k+1)}\rfloor\right)10^k\\ 
&amp;= \sum_{k=0}^n\lfloor x10^{-(n-k)}\rfloor10^k - \sum_{k=0}^n\lfloor x10^{-(n-k+1)}\rfloor10^{k+1}
\end{align*}

or if you prefer

\begin{align*}
\sum_{k=0}^nx_k10^{n-k} &amp;= \left(\lfloor x10^{-k}\rfloor - 10\lfloor x10^{-(k+1)}\rfloor\right)10^{n-k}\\ 
&amp;= \sum_{k=0}^n\lfloor x10^{-k}\rfloor10^{n-k} - \sum_{k=0}^n\lfloor x10^{-(k+1)}\rfloor10^{n-k+1}.
\end{align*}

We can simplify this even further. Note that $\lfloor x10^{-n+1}\rfloor = 0$ so the final term in the second sum is zero. Now shift the index in the second sum so that it begins at $k = 1$:

\begin{align*}
&amp;\sum_{k=0}^n\lfloor x10^{-k}\rfloor10^{n-k} - \sum_{k=0}^n\lfloor x10^{-(k+1)}\rfloor10^{n-k+1}\\ 
&amp;= \sum_{k=0}^n\lfloor x10^{-k}\rfloor10^{n-k} - \sum_{k=1}^n\lfloor x10^{-k}\rfloor10^{n-k+2}\\
&amp;= \lfloor x10^0\rfloor10^n + \sum_{k=1}^n\lfloor x10^{-k}\rfloor10^{n-k} - 100\sum_{k=1}^n\lfloor x10^{-k}\rfloor10^{n-k}\\
&amp;= x10^n - 99\sum_{k=1}^n\lfloor x10^{-k}\rfloor10^{n-k}.
\end{align*}

Therefore, given a positive integer $x$, the integer which has the same digits in the reverse order is $$x10^{\lfloor \log_{10}x\rfloor} - 99\sum_{k=1}^{\lfloor \log_{10}x\rfloor}\lfloor x10^{-k}\rfloor10^{\lfloor \log_{10}x\rfloor-k}.$$



Here's an example calculation. Let $x = 123$, then $\lfloor \log_{10}x\rfloor = 2$. As $\lfloor x10^{-1}\rfloor = \lfloor 12.3\rfloor = 12$ and $\lfloor x10^{-2}\rfloor = \lfloor 1.23\rfloor = 1$, we have 

$$123\times 10^2 - 99\left(12\times 10 + 1\times 1\right) = 123\times 100 - 99\times 121 = 12300 - 11979 = 321$$

as expected.
let number be 123. 
perform 123%10 = 3 = a
perform 123/10 =12
if not 0,then multiply a with 10, so a = 30 
perform 12%10 = b 
perform 12/10 = 1
if not 0, then multiply b with 10 &amp; a with 10,so a = 300 &amp; b = 20
perform 1%10 = c 
perform 1/10 = 0
if not 0, continue....however, as this is 0, you stop the process.
just add a+b+c. = 300+20+1 = 321


&amp; in terms of pure mathematics:

sum of [{floor of n/10^(N-1-k)}*{10^k] for k= 0 to N-1. where n is integer, &amp; N is no of digits.