Subj : Re: Reversing a number To : comp.programming From : Gerry Quinn Date : Mon Sep 12 2005 11:21 am In article , willem@stack.nl says... > Rob wrote: > ) Willem wrote: > )> )>> while (i) > )> )>> { > )> )>> n *= 10; > )> )>> n += i % 10; > )> )>> i /= 10; > )> )>> } > )> )>> return n; > ) As Jerry Quinn pointed out it's simplest to convert it to a string then > ) reverse it and convert it back again. > > That can only be simplest if 'convert to a string' is considered a simple > operation. Otherwise the above piece of code is simpler. The above bit of code *is* effectively converting it to a string (in base-10 representation, and with the characters 0-9 represented by digits), albeit in piecemeal fashion. - Gerry Quinn .