A bit pattern interprets a value as an arrangement of binary digits rather than primarily as a decimal number. For example, print an unsigned value with printf("%x", value) when its individual bits matter. section 8.3.4
Use these distinctions when choosing formatted output:
- Use "%d" or "%u" for integer values whose numerical meaning matters. section 8.3.4
- Use "%x" for bit patterns; hexadecimal corresponds more directly to binary digits than octal on architectures with 8-bit character types. section 8.3.4
- Prefer unsigned values for bit sets, because hexadecimal output receives unsigned arguments. section 8.3.4
- Match every argument with the correct format specifier and modifier; an inappropriate match produces undefined behavior and may trigger compiler warnings. section 8.3.4
Table 8.8. Hexadecimal values and bit patterns (view table figure)
| Digit |
Value |
Pattern |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
Use the hexadecimal-to-binary table to associate each hexadecimal digit with its four-bit pattern. section 8.3.4
Reading hexadecimal digits
The table maps 0 through F to values 0 through 15 and to four-bit patterns: 0 is 0000, 5 is 0101, and F is 1111. Reading hexadecimal output therefore provides a compact view of the corresponding bits. section 8.3.4

