Go Down

Topic: printIntegerInBase suggestion (Read 1 time) previous topic - next topic


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) {
       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.


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

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131