Hexadecimal: Reading, Arithmetic & Shorthand for Binary
Hexadecimal: Reading, Arithmetic & Shorthand for Binary
This page introduces the hexadecimal system, explains its role as a shorthand for binary, and shows how to calculate with it.
Introduction
Hexadecimal (often called hex) uses base 16. Digits are 0–9 and A–F, where A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. The number written as 10₁₆ means 16 in decimal.
One hex digit represents exactly 4 binary digits (bits). This makes hexadecimal especially useful in computing.
Positional values in hexadecimal
Each column has a value 16 times the column to its right. This corresponds to powers of 16.
From right to left:
- 16⁰ = 1
- 16¹ = 16
- 16² = 256
- 16³ = 4096
- 16⁴ = 65 536
- 16⁵ = 1 048 576
- 16⁶ = 16 777 216
- 16⁷ = 268 435 456
Example: 0x3C0A9 = 3 × 65 536 + 12 × 4096 + 0 × 256 + 10 × 16 + 9 × 1 = 196 608 + 49 152 + 0 + 160 + 9 = 245 929₁₀.
From decimal to hexadecimal
Method: Division by 16 1. Divide the decimal number by 16. 2. Record the remainder (0–15, written 0–9 or A–F). 3. Repeat with the quotient until 0. 4. Read the remainders backwards.
Example: Convert 449₁₀ to hex 449 ÷ 16 = 28 remainder 1 28 ÷ 16 = 1 remainder 12 (C) 1 ÷ 16 = 0 remainder 1 Result: 1C1₁₆ = 0x1C1.
Binary to hexadecimal
Group binary digits into blocks of 4, starting from the right. Convert each block into one hex digit.
Example: 110101111100₂ → group 1101 0111 1100 → D7C₁₆ = 0xD7C.
Hexadecimal to binary
Expand each hex digit into 4 binary digits.
Example: 0x2F = 2 = 0010, F = 1111 → 00101111₂.
Arithmetic in hexadecimal
Hex arithmetic follows the same principles as decimal, but carries occur after F (15).
Addition example: 0x2F + 0x17 2F₁₆ = 47₁₀, 17₁₆ = 23₁₀ 47 + 23 = 70 70 = 46₁₆ So 0x2F + 0x17 = 0x46.
Subtraction example: 0x92 − 0x4F 92₁₆ = 146₁₀, 4F₁₆ = 79₁₀ 146 − 79 = 67 67 = 43₁₆ So 0x92 − 0x4F = 0x43.
Common hexadecimal values
Some values are especially common in computing and are useful to memorize:
- 0x1000 = 4096 (4 KiB, memory page size)
- 0x10000 = 65 536 (64 KiB, maximum memory size of early 8-bit systems)
- 0x100000 = 1 MiB
- 0x40000000 = 1 GiB
Notation conventions
Modern programming languages typically use the prefix 0x for hexadecimal numbers.
- Example: 0xCAFEC0DE.
Older sources may use a trailing H instead, e.g. 1C1H. Both upper- and lowercase letters are valid: 0x2F or 0x2f.