28 lines
531 B
C
28 lines
531 B
C
#include <stdint.h>
|
|
|
|
#include "string.h"
|
|
#include "terminal.h"
|
|
|
|
int print_int_base(int64_t number, const char *prefix, const char *base)
|
|
{
|
|
const int base_size = strlen(base);
|
|
uint64_t div = 1;
|
|
uint32_t tmp;
|
|
int rv = 0;
|
|
|
|
if (prefix)
|
|
terminal_writestring(prefix);
|
|
if (number < 0) {
|
|
rv += terminal_putchar('-');
|
|
tmp = -1 * number;
|
|
} else {
|
|
tmp = number;
|
|
}
|
|
while (div <= tmp / base_size)
|
|
div *= base_size;
|
|
while (div > 0) {
|
|
rv += terminal_putchar(base[tmp / div % base_size]);
|
|
div /= base_size;
|
|
}
|
|
return rv;
|
|
} |