Machine independent C library for printing the binary representation of data types to stdout
You can just call putchar(), which automatically prints to stdout:

putchar('1');

The conditionals can instead be a ternary statement within putchar():

putchar(n &amp; mask ? '1' : '0');



putchar is often better suited for single-character output. putchar only has to pass a character directly to the output. This particular code isn't exactly performance-critical but it's useful to acquire good coding habits from the beginning.