3
$\begingroup$

How can I revert the order of digits of an integer?

If x1 = 59097585 then I want to receive x2 = 58579095.

$\endgroup$
  • 4
    $\begingroup$ Take a look at IntegerDigits, FromDigits and Reverse. $\endgroup$ – JungHwan Min May 26 '18 at 8:49
7
$\begingroup$

There's a builtin IntegerReverse function:

IntegerReverse[59097585]

58579095

$\endgroup$
4
$\begingroup$
FromDigits @ StringReverse @ ToString @ x1 (* or *)
FromDigits @ StringReverse @ IntegerString @ x1

58579095

or

With[{id = IntegerDigits[x1]}, 10^Range[0, Length[id] - 1].id]

58579095

$\endgroup$

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