Add %b to print() to print integers in binary
This commit is contained in:
parent
2bd44726e4
commit
583765fd7c
@ -58,6 +58,16 @@ void putx(unsigned int i) {
|
||||
}
|
||||
}
|
||||
|
||||
void putb(unsigned int i) {
|
||||
int j;
|
||||
|
||||
puts("0b");
|
||||
|
||||
for (j = 0; j < 32; j++) {
|
||||
putc((i>>(31-j)) & 1 ? '1' : '0');
|
||||
}
|
||||
}
|
||||
|
||||
int print(char *fmt, ...) {
|
||||
char *c;
|
||||
va_list arg;
|
||||
@ -81,6 +91,9 @@ int print(char *fmt, ...) {
|
||||
case 'x':
|
||||
putx(va_arg(arg, unsigned int));
|
||||
break;
|
||||
case 'b':
|
||||
putb(va_arg(arg, unsigned int));
|
||||
break;
|
||||
default:
|
||||
puts("\nError: print(): Invalid formatting character: '");
|
||||
putc(*c);
|
||||
|
Loading…
Reference in New Issue
Block a user