Update printing in hex format to be more straight-forward
This commit is contained in:
parent
a7bd2c8ae6
commit
b531496f8e
@ -45,26 +45,17 @@ void puti(int i)
|
||||
}
|
||||
|
||||
void putx(unsigned int i) {
|
||||
unsigned int left = i;
|
||||
char buf[1 << (sizeof(int)*8) / 16];
|
||||
char *p = buf;
|
||||
int j;
|
||||
|
||||
puts("0x");
|
||||
if (!i)
|
||||
putc('0');
|
||||
|
||||
while (left) {
|
||||
unsigned int remainder = left % 16;
|
||||
left /= 16;
|
||||
if (remainder < 10)
|
||||
*p = ('0'-0) + remainder;
|
||||
for (j = 0; j < 8; j++) {
|
||||
unsigned int toprint = (i >> (4*(7-j))) & 0xf;
|
||||
if (toprint < 10)
|
||||
putc(('0'-0) + toprint);
|
||||
else
|
||||
*p = ('a'-10) + remainder;
|
||||
p++;
|
||||
putc(('a'-10) + toprint);
|
||||
}
|
||||
|
||||
while (p-- != buf)
|
||||
putc(*p);
|
||||
}
|
||||
|
||||
int print(char *fmt, ...) {
|
||||
|
Loading…
Reference in New Issue
Block a user