Pages: [1]   Go Down
Author Topic: printIntegerInBase suggestion  (Read 742 times)
0 Members and 1 Guest are viewing this topic.
Austin, TX
Offline Offline
Full Member
***
Karma: 1
Posts: 182
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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);
        }
}
Logged

Chris J. Kiick
Robot builder and all around geek.

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: