liveBook · Manning

Hexadecimal number

As explained in Modern C

A hexadecimal format is a numeric output representation using base-16 digits and, when applicable, a hexadecimal prefix.

In C, `0x7FFF` and `0x8000` denote integer constants written with base-16 digits. The prefix `0x` identifies hexadecimal notation; digits `A`–`F` extend the values beyond `0`–`9`. The same numeric value can acquire different types depending on how it is written: `0x7FFF` is signed, while `0x8000` can be unsigned when it does not fit the signed type. section 5.3

Use hexadecimal deliberately in two related situations:

  • Represent nonnegative integer constants compactly, using forms such as `0x7FFF`, `0x8000`, and `0xFFFFFFFF`. section 5.3
  • Print bit patterns with `%x` or `%X`; each hexadecimal digit corresponds directly to four bits, making the representation preferable to octal for modern 8-bit-character architectures. section 8.3.4
  • Avoid expressing negative values with hexadecimal constants: `-0x8000` remains unsigned in the relevant case, whereas decimal constants express negative values as intended. section 5.3

Reading a hexadecimal bit pattern

The hexadecimal digit `F` has value 15 and bit pattern `1111`; therefore a sequence such as `0xFFFFFFFF` exposes a 32-bit pattern compactly. Its interpretation still depends on the constant's type: the listed 32-bit example is unsigned, and applying unary minus produces `+1` through unsigned arithmetic.

How Modern C covers it

How deep it goes
Explains notation, digit patterns, constant typing, negative-value pitfalls, and printf conversion, without developing arithmetic algorithms.
Examples
Uses `0x7FFF`, `0x8000`, `0xFFFFFFFF`, `%x`, and a table mapping hexadecimal digits to four-bit patterns.
What it assumes
Assumes familiarity with C integer types and formatted output while defining hexadecimal digits and their bit patterns.
What you can do after
Apply it via C literal syntax and printf formats while recognizing unsigned interpretation and four-bit digit patterns.
How it connects
Connects hexadecimal numbers with integer constants, unsigned types, bit patterns, printf format specifiers, and octal notation.

Also explained in

Compare how 5 books explain hexadecimal number →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.