function to reverse a digits