I can print with printf
as a hex or octal number. Is there a format tag to print as binary, or arbitrary base?
I am running gcc.
printf("%d %x %o\n", 10, 10, 10); //prints "10 A 12\n"
print("%b\n", 10); // prints "%b\n"
cprintf
I can print with printf
as a hex or octal number. Is there a format tag to print as binary, or arbitrary base?
I am running gcc.
printf("%d %x %o\n", 10, 10, 10); //prints "10 A 12\n"
print("%b\n", 10); // prints "%b\n"
Best Answer
Hacky but works for me:
For multi-byte types
You need all the extra quotes unfortunately. This approach has the efficiency risks of macros (don't pass a function as the argument to
BYTE_TO_BINARY
) but avoids the memory issues and multiple invocations of strcat in some of the other proposals here.