Mathematics

How to Convert Between Hex and Decimal

Hex to decimal is place value with powers of 16, using a-f for the digits 10-15; decimal to hex is repeated division by 16, reading the remainders — converted back to a-f where needed — from bottom to top.

The hex digits: 0-9, then a-f for 10-15

Hexadecimal (base 16) needs 16 distinct digits, but only 10 numerals exist, so it borrows letters for the rest: a=10, b=11, c=12, d=13, e=14, f=15. A hex number like "2a" reads as the digit 2, then the digit a (which is 10) — not the letters "t-w-o-a" or anything alphabetic.

Hex to decimal: place value with powers of 16

Just like binary uses powers of 2, hex uses powers of 16: 1, 16, 256, and so on. For "ff" (two f digits, each worth 15): 15×16 + 15×1 = 240 + 15 = 255. For "2a": 2×16 + 10×1 = 32 + 10 = 42 — using a's value of 10 in the ones place.

Decimal to hex: repeated division by 16

Divide by 16 repeatedly, converting each remainder to its hex digit (0-9 stay as-is, 10-15 become a-f), and read bottom to top. For 255: 255÷16=15 r15, 15÷16=0 r15 — two remainders, both 15, which is "f" — giving "ff", matching the first example. For 500: 500÷16=31 r4, 31÷16=1 r15, 1÷16=0 r1 — remainders 4, 15 (f), 1, read bottom to top gives "1f4".

Why hex numbers can look shorter than binary or decimal

Each hex digit packs in 16 possible values instead of decimal's 10 or binary's 2, so the same quantity needs fewer digits to write in hex. 255 takes 3 decimal digits but only 2 hex digits ("ff") — and, as the companion article on hex as binary shorthand shows, exactly 8 binary digits, since one hex digit always corresponds to a fixed 4 binary digits.