Data Representation & Number Systems

octal

/ OCK-tul /

Octal is another human-friendly shorthand for binary, the older sibling of hexadecimal. It is base eight, using just the digits 0 through 7. Like hex, its appeal is that eight is a power of two — eight is 2^3 — so each single octal digit packs exactly 3 bits. Before hexadecimal became dominant, octal was the popular way to write binary on machines whose word sizes were multiples of three bits.

To convert binary to octal, group the bits in threes from the right and read each group as one octal digit: 0b101 is 5, 0b110 is 6, so 0b101110 is 56 in octal. Octal numbers are often marked with a leading zero or the prefix 0o, as in 0o56. The arithmetic is the same place-value idea as always: 0o56 means 5 times 8 + 6 = 46 in decimal.

Today octal is mostly a niche notation, but one place it still rules is Unix file permissions: a mode like 0o755 packs three groups of three permission bits (read, write, execute) for owner, group, and others, which is exactly why three-bit octal digits fit so neatly. A historical footnote and a real gotcha: in many programming languages a number written with a leading zero, like 0755, is silently interpreted as octal, so 011 is the value nine, not eleven — a bug that has surprised many a programmer.

The binary 0b110101 groups as 110 101, which is 0o65 in octal and 6 times 8 + 5 = 53 in decimal. The Unix permission 0o644 means owner read+write, group read, others read.

Each octal digit maps to exactly three bits; permissions are octal's lasting home.

In C, Java, and others a leading zero means octal: 010 is the value 8, not 10. This silent rule is a notorious source of off-by-surprise bugs, which is why newer languages prefer the explicit 0o prefix.

Also called
base 8base-88 進位