Data representation · foundation
Hexadecimal
Hexadecimal is base-16 positional notation using digits 0–9 and A–F. One hexadecimal digit represents exactly four bits, making hex a compact, reversible notation for binary data.
Why it matters
Hex appears in memory addresses, byte dumps, colors, Unicode code points, bit masks, hashes, and protocol documentation because it preserves binary boundaries more clearly than decimal.
Mental model
How to reason about hexadecimal
Translate one hex digit at a time into a four-bit group. For numeric conversion, positions have weights 1, 16, 256, and so on; for raw bytes, two hex digits display one eight-bit byte.
Analogy
Hex is shorthand for binary in four-switch syllables: each compact symbol expands to one exact group of four switches without approximation.
Examples
See the boundary, not just the happy path
Worked example · Convert a hex value
0x2F = 2 × 16 + 15 = 47F represents decimal 15. The 2 occupies the sixteens position, so the total is 32 + 15.
Worked example · Read a byte dump
printf 'ABC' | xxd -g 1A typical xxd output shows bytes 41 42 43 in hex. Each pair is one byte; a character encoding such as ASCII or UTF-8 explains why those bytes represent ABC.
Useful contrast · Prefix changes notation
0x10 is decimal 16, while decimal 10 is binary 1010The sequence of glyphs 10 has no base-independent numeric value. Language prefixes and surrounding format establish the radix.
Common mistakes
Misconceptions to remove early
Treating a hex dump as decoded meaning
Hex displays bytes compactly but does not tell whether they are text, integers, compressed data, or instructions. A format and encoding are still required.
Forgetting fixed-width padding
The values 0xA and 0x0A are numerically equal, but 0A communicates a complete byte. Width can be essential when reading protocols and masks.
Quick check
Can you predict the result?
1. How many bits does one hexadecimal digit represent?
- • 4 bits
- • 8 bits
- • 16 bits
2. Why are two hex digits enough to display one ordinary eight-bit byte?
Keep building