Go Down

Topic: printIntegerInBase suggestion (Read 884 times) previous topic - next topic

ckiick

The following implementation of printIntegerInBase shortens the core
by 138 bytes.  It should be faster as well, since it only has 1 loop.

Code: [Select]

void printIntegerInBase(unsigned long n, unsigned long base)
{
       int d;

       if (n == 0) {
               printByte('0');
               return;
       }
       for ( ; n > 0; n /= base) {
               d = n % base;
               printByte( d < 10 ?
                       '0' + d :
                       'A' + d - 10);
       }
}

Chris J. Kiick
Robot builder and all around geek.

mellis

Unfortunately, it prints the digits of the number in reverse order.

Go Up