SyntaxFix
Write A Post
Hire A Developer
Questions
Based on dirkgently's answer, but fixing his two bugs, and always printing a fixed number of digits:
void printbits(unsigned char v) { int i; // for C89 compatability for(i = 7; i >= 0; i--) putchar('0' + ((v >> i) & 1)); }