Data Representation & Number Systems

hexadecimal

/ HEK-suh-DESS-ih-mul /

Long strings of 0s and 1s are hard for humans to read without losing their place — 0b1111111100000000 is a blur. Hexadecimal is a compact shorthand for binary that engineers use everywhere. It is base sixteen, so it needs sixteen digit symbols: 0 through 9, then the letters A, B, C, D, E, F to stand for the values ten through fifteen. The point is not new arithmetic; it is a far more readable way to write the very same bits.

The magic is that sixteen is exactly 2^4, so each single hex digit corresponds to exactly 4 bits, and one byte (8 bits) is always exactly two hex digits. To convert, chop the binary into groups of 4 from the right and translate each group: 0b1100 is 0xC (12), 0b1010 is 0xA (10), so 0b11001010 is 0xCA. Going back is just as mechanical: expand each hex digit into its 4-bit pattern. We usually mark a hex number with the prefix 0x, as in 0x2F, which is 2 times 16 + 15 = 47 in decimal.

Hex shows up constantly: memory addresses, byte values in a debugger, colours on the web (0xFF0000 is pure red, two hex digits each for red, green, blue), and Unicode code points (U+1F600). It is purely a notation for humans — the machine still stores plain binary; hex is just a comfortable lens. The classic beginner trap is forgetting that the letters A through F are digits here, not text: 0xFF is the single number 255, not two F characters.

0x2F in binary is 0010 1111, which is 2 times 16 + 15 = 47 in decimal. The web colour 0x00FF00 is pure green: 0x00 red, 0xFF green, 0x00 blue.

Each hex digit maps to exactly four bits, so a byte is always two hex digits.

Hex is a display convenience, not a different kind of number: 0xFF, 0b11111111, and 255 are the same value. Always note the prefix, because '10' means ten in decimal, two in binary, and sixteen in hex.

Also called
hexbase 16base-1616 進位