Octal to Text

Turn octal byte codes back into readable characters.

Run the Unix command od -c on an old file and the byte values come out in octal, not hex. That is not an arbitrary choice — the command’s name literally stands for octal dump, a holdover from an era when octal, not hex, was the default way to inspect a file byte by byte.

od really does mean octal dump

Before hex dumps became the near-universal standard, Unix systems displayed raw bytes in octal by default, and the od utility keeps that behaviour even now — you have to ask it explicitly for hex with a flag if that is what you want. It is one of the oldest command names still in daily use, dating back to the earliest versions of Unix.

Reading its output means doing the same job as any octal-to-text conversion: take each octal code, convert it to a decimal byte value, and look up the character that value represents.

A worked conversion

Suppose od -c shows you the octal code 115 for a byte in a file. Converting to decimal: (1 × 64) + (1 × 8) + 5 = 77. Decimal 77 is the letter M in ASCII — the thirteenth letter of the alphabet, sitting 12 places after A at 65.

A space character shows up as octal 040, which converts to (4 × 8) = 32, the standard ASCII code for a space. Recognising a handful of these by sight — 040 for space, 012 for a line break — is genuinely useful once you read octal dumps often enough.

Where octal-encoded text still turns up

  • tar archive headers — The POSIX ustar format stores a file’s size and permission mode as octal digits written out as plain text inside the archive header, a design choice that predates most modern binary encodings.
  • The od command — Its default output format is octal, a direct legacy of early Unix tooling, even though most people reach for a hex-based alternative today.
  • printf-style format strings — The %o specifier, found in C and many languages descended from it, formats an integer as octal text for exactly this kind of legacy compatibility.

Decoding octal text by hand

  1. Take each octal code, one character at a time.
  2. Convert it to decimal: multiply the hundreds-equivalent digit by 64, the middle digit by 8, add the last digit.
  3. Look up that decimal value in an ASCII table to find the character.
  4. Repeat for every code in the sequence to reconstruct the full text.

Octal to text questions

Why does od default to octal instead of hex?

Because the tool predates hex dumps becoming standard practice. Its name and default behaviour are both leftovers from an earlier convention in Unix, and later versions added a hex option without changing the historical default.

Is octal-encoded text still common in modern files?

Rarely as the primary encoding, but it survives in specific formats, most notably the size and permission fields inside a POSIX tar archive header, which are stored as octal ASCII digits.

Can every byte value be represented as three octal digits?

Yes. Three octal digits cover 0 through 511, comfortably more than the 0 to 255 range a single byte needs, so there is never a value that will not fit.

Why is 040 the octal code for a space and not something rounder?

Because ASCII assigned decimal 32 to the space character back in the 1960s, for reasons tied to how control codes were organised, and 32 happens to convert to octal 40.

Does this tool handle multi-byte characters like accented letters?

It converts the octal byte values you give it; how those bytes should be grouped into characters depends on the text encoding, and mixing encodings is the most common source of garbled results.

Cookie
We care about your data and would love to use cookies to improve your experience.