A hexadecimal number uses sixteen digits: 0–9 and A–F, where A–F represent 10–15. In C, an integer hexadecimal literal begins with 0x or 0X, so 0xbeaf has value 48,815 and 0XBEAF denotes the same value. section 5.3
Use hexadecimal notation for these closely related tasks:
- Write integer constants with a 0x or 0X prefix, followed by hexadecimal digits. section 5.3
- Read bit patterns compactly: each hexadecimal digit corresponds to four binary bits, making hexadecimal preferable to binary for large bit sets. section 8.4.4
- Distinguish integer literals from hexadecimal floating-point literals such as 0x1.7aP-13, whose exponent is decimal but whose value is based on a power of two. section 5.3
- Print an unsigned bit pattern with %x or %X; use %d or %u when the displayed meaning is an ordinary integer value. section 8.4.4
Printing a hexadecimal bit pattern
unsigned value = 0xBEAF; printf("%x\n", value); /* prints beaf */ printf("%u\n", value); /* prints 48815 */ The literal supplies an integer value; the format specifier chooses whether output emphasizes its hexadecimal representation or its decimal magnitude. section 5.3 section 8.4.4




