inverse number (unsigned)

Hello, I am new to Arduino, and I'm trying to write an easy program that can inverse a number but I am stuck in this problems, for example, if the integer has the value 123456, then I want to inverse that to 654321, any tips or codes for reference? Thanks. :cry: :cry:

Which data type is the number held in ?

integer
thanks!

morsta111:
integer
thanks!

An unsigned long int (or uint32_t) I presume

Do you know how to separate the number into its digits ?

i am not sure, is it number % 10?

for (i = 0; i < digits; i++)
{
  out = (out * 10) + (in % 10)
  in /= 10
}

…which just leaves the problem of determining the value of “digits”

    unsigned long in = 123456;
    unsigned long out = 0;
    while (in != 0) { // as long as 'in' has digits left
        out *= 10;      // shift 'out' one digit to the left
        out += in % 10; // add the rightmost digit of 'in' to 'out'
        in /= 10;       // shift 'in' one digit to the right
    }

Intermediate values to see how it works:

     in    out
 123456      0
  12345      6
   1234     65
    123    654
     12   6543
      1  65432
      0 654321

Pieter