version 1.30, 2003/11/17 17:12:10 |
version 1.31, 2005/05/29 18:44:36 |
|
|
void |
void |
pbnum(int n) |
pbnum(int n) |
{ |
{ |
|
pbnumbase(n, 10, 0); |
|
} |
|
|
|
void |
|
pbnumbase(int n, int base, int d) |
|
{ |
|
static char digits[36] = "0123456789abcdefghijklmnopqrstuvwxyz"; |
int num; |
int num; |
|
int printed = 0; |
|
|
|
if (base > 36) |
|
errx(1, "base %d > 36: not supported", base); |
|
|
|
if (base < 2) |
|
errx(1, "bad base %d for conversion", base); |
|
|
num = (n < 0) ? -n : n; |
num = (n < 0) ? -n : n; |
do { |
do { |
putback(num % 10 + '0'); |
putback(digits[num % base]); |
|
printed++; |
} |
} |
while ((num /= 10) > 0); |
while ((num /= base) > 0); |
|
|
|
if (n < 0) |
|
printed++; |
|
while (printed++ < d) |
|
putback('0'); |
|
|
if (n < 0) |
if (n < 0) |
putback('-'); |
putback('-'); |