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
void print_binary(unsigned int n) { unsigned int mask = 0; /* this grotesque hack creates a bit pattern 1000... */ /* regardless of the size of an unsigned int */ mask = ~mask ^ (~mask >> 1); for(; mask != 0; mask >>= 1) { putchar((n & mask) ? '1' : '0'); } }