TITLE: How to reverse digits of an integer mathematically?
QUESTION [12 upvotes]: Is there a mathematical way to reverse digits of an integer mathematically? for example:
 $18539 \rightarrow 93581$

REPLY [5 votes]: Here's a recursive formula:
$$R(N)=U(N)10^{[log(N)]}+R([N/10])$$
where
$$U(N)=N-10[N/10]$$
is the "unit" digit of $N$ (i.e., the digit in the "ones" column), and $R(0)$ is understood to equal $0$.  The logarithm is base $10$, and the square brackets indicate the greatest-integer (floor) function.
Note:  reversing digits is not an involution when $U(N)=0$.  E.g., $R(100)=1$, but R($1)\neq100$.
Added later:  It occurs to me that the recursive formula adapts nicely to digit reversal in any base:
$$R_b(N) = U_b(N)b^{[log_b(N)]}+R_b([N/b])$$
where
$$U_b(N)=N-b[N/b]$$