I would do this with math:

If your number is 12321 how do you single out the first digit?
How do you single out the last digit?

After you have singled out the first and last digit and compared them how do you move on to the next digits to compare?

Hint: the number 10, division, and modulus are important