liveBook · Manning

Hexadecimal number

As explained in Modern C, Third Edition

A hexadecimal format represents a value using base-sixteen digits.

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

How Modern C, Third Edition covers it

How deep it goes
Defines integer and floating-point syntax, digit values, bit mappings, and printf choices without developing arithmetic algorithms.
Examples
Uses 0xbeaf, 0x7FFF'FFFF, hexadecimal digit patterns, and %x output as concrete examples.
What it assumes
Assumes familiarity with numerical constants and C output; teaches hexadecimal prefixes, digits, values, and bit-pattern correspondence.
What you can do after
Apply it via C literals and printf formats to write, interpret, and display integer bit patterns.
How it connects
Connects hexadecimal numbers with integer literals, binary literals, bit patterns, unsigned types, printf, and floating-point literals.

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, Third Edition. The section links point to the parts of the book it draws on.