Go Down

Topic: printIntegerInBase suggestion (Read 955 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
 


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!

Arduino
via Egeo 16
Torino, 10131
Italy