Data Representation: Bits, Bytes & Numbers

binary, hexadecimal, and octal

/ HEKS-uh-DESS-ih-muhl /

We count in decimal — base ten — almost certainly because we have ten fingers. But the choice of ten is just a convention. A number system is built from a base: how many distinct digit-symbols you have, and how much each position is worth. Computers find some bases far more natural than ten, and you will meet three of them constantly: binary, hexadecimal, and (occasionally) octal.

Binary is base 2: only the digits 0 and 1, and each position is worth twice the one to its right (1, 2, 4, 8, 16, ...). It matches hardware exactly, since each digit is one bit. Hexadecimal is base 16: sixteen digit-symbols 0-9 then a, b, c, d, e, f (for ten through fifteen), each position worth sixteen times the last. Its charm is that one hex digit equals exactly four bits (a nibble), so hex is a short, exact shorthand for binary. Octal is base 8: digits 0-7, each position worth eight times the last, so one octal digit equals exactly three bits; it shows up mainly in old Unix file permissions like 0755. To avoid confusion, write the base with a prefix: 0x for hex (0x2A), 0b for binary (0b101010), a leading 0 for octal (0755), and nothing for decimal (42).

These all name the SAME numbers — only the spelling changes. The value forty-two is 42 in decimal, 0x2A in hex, 0b101010 in binary, and 052 in octal; the quantity is identical. Programmers prefer hex when they care about the actual bits — colours like 0xFF0000, memory addresses, and bit masks — because each hex digit maps to a tidy group of four bits you can picture at a glance, whereas long binary strings are easy to miscount.

The number 42 in four bases: decimal 42, hex 0x2A, binary 0b101010, octal 052. The colour red is hex 0xFF0000 — easier to read than 0b111111110000000000000000.

Same value, different spelling; one hex digit = four bits.

A leading zero in C source means octal, so 010 is the number EIGHT, not ten — a classic trap when someone pads numbers with zeros for alignment.

Also called
base 2base 16base 8進位制