Skip to content
AgileLogics

Hexadecimal to Octal

Converts a base-16 (hexadecimal) number into its base-8 (octal) equivalent.

How it works

Enter a hex number (e.g. ff) and click Convert.

How do you convert hex to octal?

The cleanest route goes through binary. Write each hex digit as 4 bits, then regroup the whole bit string into 3-bit chunks starting from the right, and convert each chunk to a digit from 0 to 7. Hex 1ED is 0001 1110 1101 in binary, regrouped as 000 111 101 101, which reads as octal 755.

You can't map hex digits straight to octal digits, because 4-bit and 3-bit groups only line up every 12 bits. That's what makes this conversion more error-prone by hand than hex to binary or binary to octal.

Using the tool

  1. Enter hex digits, for example 1ED or 1ed.
  2. Click Convert.
  3. Copy the octal result, 755.

Don't include 0x, and don't put spaces inside the value. Leading and trailing whitespace is fine.

Worked example: 1ED, regrouping the bits

Step 1: expand each hex digit to four bits.

Hex digit 1 E D
Bits 0001 1110 1101

Step 2: join and regroup in threes from the right. The 12 bits 000111101101 become 000 111 101 101.

Step 3: read each triplet. 000 is 0, 111 is 7, 101 is 5, 101 is 5. Drop the leading zero and the answer is 755.

If the bit count isn't a multiple of three, pad the leftmost group with zeros. Always regroup from the right-hand end, the ones place, or every digit shifts.

Octal escapes for bytes

The most practical reason to convert hex to octal is writing byte values as octal escape sequences. C, shell printf and Python string literals all accept a backslash followed by up to three octal digits (Python's escape sequence table lists \ooo). Hex dumps show bytes in hex, so you convert:

Byte (hex) Octal Escape What it is
0a 12 \012 line feed
1b 33 \033 ESC, the start of ANSI terminal color codes like \033[0m
20 40 \040 space
41 101 \101 the letter A
7f 177 \177 DEL
ff 377 \377 highest byte value

Pad short results to three digits when you write the escape (\012, not \12), so a following digit isn't swallowed into the escape.

File modes from a hex dump

Unix stores a file's type and permissions in one number, st_mode, which is conventionally read in octal. In a binary dump of a filesystem or archive header you'll meet it in hex instead, and converting reveals the familiar mode:

Hex in the dump Octal Meaning
81a4 100644 regular file, rw-r--r--
41ed 40755 directory, rwxr-xr-x
a1ff 120777 symbolic link, rwxrwxrwx

The leading digits (10, 4, 12) are the file type bits listed in inode(7), and the last three digits are the permissions.

Quick checks and limits

  • fff becomes 7777. Every 12 bits of 1s give four 7s, a nice sanity check that 4-bit and 3-bit groups meet at 12.
  • Letters are case-insensitive: FF and ff both give 377.
  • No negative numbers, no fractions, no separators.
  • Input above 1fffffffffffff is refused rather than rounded, because the conversion uses JavaScript numbers, which can't represent every integer past 2^53 - 1.
  • It runs locally in your browser.

Related tools

  • Octal to hexadecimal does the reverse, for instance turning a chmod mode into the hex you'd see in a dump.
  • Hex to binary shows the intermediate bit string from step 1.
  • Binary to octal handles step 3 and maps each octal digit to read, write and execute.
  • The ASCII table lists the hex code of every character, so you can find the byte before converting it.

Last updated

Frequently asked questions

Can you convert hex to octal digit by digit?
Not directly, because one hex digit is 4 bits and one octal digit is 3 bits, so the boundaries don't line up. Expand the hex to binary, regroup the bits in threes from the right, and read each group as an octal digit. Going through decimal also works but takes longer.
What is FF in octal?
377. That's why the highest byte value is written \377 as an octal escape in C and Python strings.
Does the converter accept 0x or produce a 0o prefix?
Neither. Enter bare hex digits (any case) and you get bare octal digits back. 0xff causes an "Enter a valid hexadecimal number" error; ff gives 377.
Is there a size limit?
Yes. The largest accepted value is 1fffffffffffff, which converts to 377777777777777777. Larger values show "That number is too large to convert precisely."