Hex to Decimal

Hex to octal converter

Type hex or octal and the other side updates. The steps panel shows how the bits regroup from fours into threes. The sections below cover the binary regrouping method, the decimal route, a digit table, octal to hex, where octal appears, code in several languages, practice problems and common questions.

Regroup the bits 4 bits per hex digit, 3 bits per octal digit

Decimal
Binary
C / Python style
Unix permission

How to convert hex to octal

The binary regrouping method

Convert each hex digit to 4 bits, join the bits, regroup them into sets of 3 from the right, and read each group as an octal digit. This works because 16 = 2⁴ and 8 = 2³, so both bases map cleanly onto binary.

  1. Write each hex digit as its 4-bit binary pattern.
  2. Join all the bits into a single string.
  3. Pad the left side with zeros until the total number of bits is a multiple of 3.
  4. Split the bits into groups of 3 from the right.
  5. Replace each 3-bit group with its octal digit (0 through 7).

Type a hex value in the picture to watch the same bits move from groups of four into groups of three.

Example 1: convert 1ED to octal

Hex digit4-bit binary
10001
E1110
D1101

Joined: 000111101101. Regroup into threes from the right: 000 111 101 101. Read the octal digits: 0755. Drop the leading zero: 1ED₁₆ = 755₈. The converter above shows the same regrouping in its steps panel.

Example 2: convert FF to octal

Hex digit4-bit binary
F1111
F1111

Joined: 11111111 (8 bits). Pad to 9 bits: 011111111. Regroup: 011 111 111. Octal digits: 377. So FF₁₆ = 377₈. Decimal check: FF = 255, and 3 × 64 + 7 × 8 + 7 = 255.

Example 3: convert A5 to octal

Hex digit4-bit binary
A1010
50101

Joined: 10100101 (8 bits). Pad to 9 bits: 010100101. Regroup: 010 100 101. Octal digits: 245. So A5₁₆ = 245₈.

Example 4: convert DEADBEEF to octal

Hex digitDEADBEEF
4-bit binary11011110101011011011111011101111

Joined: 11011110101011011011111011101111 (32 bits). Pad to 33 bits, the next multiple of 3: 011011110101011011011111011101111. Regroup into threes: 011 011 110 101 011 011 011 111 011 101 111. Octal digits: 33653337357. So DEADBEEF₁₆ = 33653337357₈.

That is 11 octal digits for 8 hex digits, because each hex digit carries slightly more information than each octal digit (4 bits against 3 bits).

Hex to octal through decimal

An alternative method converts hex to decimal first, then divides repeatedly by 8. This route is slower, but it helps when you want to check the binary method or prefer decimal arithmetic.

  1. Convert the hex number to decimal: multiply each digit by its power of 16 and add the results.
  2. Divide the decimal number by 8 and write down the remainder.
  3. Divide the quotient by 8 again and write down the remainder.
  4. Repeat until the quotient is 0.
  5. Read the remainders from bottom to top. That sequence is the octal number.

Example: convert B8A to octal via decimal

Step 1: B × 256 = 2,816, 8 × 16 = 128 and A × 1 = 10. The decimal total is 2,816 + 128 + 10 = 2,954.

Step 2: 2,954 ÷ 8 = 369 remainder 2. Then 369 ÷ 8 = 46 remainder 1, 46 ÷ 8 = 5 remainder 6, and 5 ÷ 8 = 0 remainder 5. Read the remainders from bottom to top: 5612₈.

The binary method agrees: B = 1011, 8 = 1000 and A = 1010 give 101110001010, which regroups as 101 110 001 010 and reads 5612.

Hex to octal conversion table

Each single hex digit (0 to F) maps to one or two octal digits through its 4-bit binary pattern. Tap a digit in the picture to see how its bits regroup.

Hex digits 0 through 7 keep the same value in octal. Hex digits 8 through F become two-digit octal numbers (10 through 17), because values above 7 need an extra octal digit.

HexBinaryOctalDecimal
0000000
1000111
2001022
3001133
4010044
5010155
6011066
7011177
81000108
91001119
A10101210
B10111311
C11001412
D11011513
E11101614
F11111715

The 3-bit patterns for octal digits are:

Octal digit3 bits
0000
1001
2010
3011
4100
5101
6110
7111

Octal to hex conversion

To reverse the process, write each octal digit as 3 bits, join the bits, regroup them into fours from the right, and read each group as a hex digit.

Example: convert 755 to hex

7 = 111, 5 = 101 and 5 = 101. Joined: 111101101 (9 bits). Pad to 12 bits: 000111101101. Regroup into fours: 0001 1110 1101. Hex digits: 1ED. So 755₈ = 1ED₁₆.

Where octal is used

Unix and POSIX file permissions

Octal appears most often in file permission modes on Unix and Linux systems. Each of the three octal digits holds the read (4), write (2) and execute (1) bits for the owner, the group and others. Switch the boxes to see the digits change.

The chmod command takes these octal values directly. chmod 755 script.sh gives the owner read, write and execute rights, and gives the group and others read and execute rights.

OctalHexSymbolicTypical use
7551EDrwxr-xr-xPrograms and directories
6441A4rw-r--r--Ordinary files
600180rw-------Private files such as SSH keys
7771FFrwxrwxrwxOpen to everyone (avoid in production)

Shell scripts and printf

POSIX printf accepts octal escape sequences. The ASCII escape character is 1B in hex and 033 in octal, so shell scripts write printf '\033[1m' to start bold text. Converting hex byte values to octal is a common task when writing portable shell scripts that must avoid non-POSIX escape syntax.

Other uses

Octal was more common in early computing, when word sizes were multiples of 3 bits (12-bit, 24-bit and 36-bit machines). PDP-8 addresses and instructions were written in octal. Modern systems favour hex because word sizes are now multiples of 4 bits (8, 16, 32 and 64 bits), but octal persists in Unix permissions and some display applications.

Hex to octal in programming

Pick a language to see the call and its output for your value.

Python

h = '1ED'
n = int(h, 16)
oct(n)             # '0o755'
oct(n)[2:]         # '755' (without prefix)
f'{n:o}'           # '755'

Python’s int() with base 16 parses the hex string, and oct() or the o format specifier produces the octal. For the full guide, see hex to decimal in Python.

JavaScript

const n = parseInt('1ED', 16);
n.toString(8);  // '755'

parseInt with radix 16 parses the hex, and toString(8) returns the octal string. For the full guide, see hex to decimal in JavaScript.

C

#include <stdio.h>
int main(void) {
    unsigned n = 0x1ED;
    printf("%o\n", n);   /* prints 755 */
    return 0;
}

The %o format specifier in printf outputs octal. For the full guide, see hex to decimal in C.

Bash

printf '%o\n' 0x1ED                 # prints 755
echo "obase=8;ibase=16;1ED" | bc   # prints 755

Bash printf converts a hex literal (0x prefix) to octal with the %o specifier. bc handles arbitrary-size numbers when the value exceeds 64 bits.

Other languages

LanguageMethodExampleResult
JavaInteger.toOctalString()Integer.toOctalString(0x1ED)"755"
Excel=HEX2OCT()=HEX2OCT("1ED")"755"
PHPdecoct(hexdec())decoct(hexdec('1ED'))"755"
SwiftString(n, radix: 8)String(0x1ED, radix: 8)"755"

Practice problems

Convert these values by hand, then check each answer with the converter above.

  1. 3C = 0011 1100 → 000 111 100 → 74₈.
  2. A0 = 1010 0000 → 010 100 000 → 240₈.
  3. 7FFF = 0111 1111 1111 1111 → 000 111 111 111 111 111 → 77777₈.
  4. C0FFEE = 1100 0000 1111 1111 1110 1110 → 110 000 001 111 111 111 101 110 → 60177756₈.
  5. Octal 154 = 001 101 100, which regroups as 0110 1100 → 6C₁₆.
  6. Four hex digits are 16 bits. 16 ÷ 3 = 5 remainder 1, so the answer is 6 octal digits. The leading digit uses a single bit.

Frequently asked questions

How do you convert hex to octal?
Write each hex digit as 4 bits, join the bits, regroup them into sets of 3 from the right, and read each 3-bit group as an octal digit. No decimal arithmetic is needed because both hex and octal map directly to binary (16 = 2⁴ and 8 = 2³).
Is octal the same as hex?
No. Octal is base 8 (digits 0 to 7) and hex is base 16 (digits 0 to 9 and A to F). Both are shorthand for binary, but hex groups 4 bits per digit and octal groups 3 bits per digit.
When would you use octal instead of hex?
Use octal for Unix and POSIX file permissions and shell escape sequences, where the standard notation is base 8. Hex is the default everywhere else in modern computing because current word sizes (8, 16, 32 and 64 bits) divide evenly into 4-bit nibbles.
What is hex F in octal?
Hex F is 17 in octal. F = 15 in decimal, and 15 in octal is 1 × 8 + 7 = 17.
Why does the binary regrouping method work?
Hex digits map to 4 bits and octal digits map to 3 bits, so the same binary string can be read in either grouping without changing its value. The conversion moves the grouping boundaries instead of recalculating the number.
How many octal digits does a hex number need?
Multiply the number of hex digits by 4, divide by 3 and round up. One hex digit (4 bits) needs at most 2 octal digits. Two hex digits (8 bits) need 3, four hex digits (16 bits) need 6, and eight hex digits (32 bits) need 11.
Can you convert hex to octal without binary?
Yes. Convert hex to decimal first, then divide the decimal number by 8 repeatedly and read the remainders from bottom to top. The decimal route involves more arithmetic but produces the same result.
What is 0o755 in hex?
0o755 is 0x1ED. Octal 755 = 7 × 64 + 5 × 8 + 5 = 493 in decimal, and 493 = 1 × 256 + 14 × 16 + 13 = 1ED in hex. This is the standard Unix permission for executable files and directories (rwxr-xr-x).