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.
- Write each hex digit as its 4-bit binary pattern.
- Join all the bits into a single string.
- Pad the left side with zeros until the total number of bits is a multiple of 3.
- Split the bits into groups of 3 from the right.
- 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 digit | 4-bit binary |
|---|---|
| 1 | 0001 |
| E | 1110 |
| D | 1101 |
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 digit | 4-bit binary |
|---|---|
| F | 1111 |
| F | 1111 |
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 digit | 4-bit binary |
|---|---|
| A | 1010 |
| 5 | 0101 |
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 digit | D | E | A | D | B | E | E | F |
|---|---|---|---|---|---|---|---|---|
| 4-bit binary | 1101 | 1110 | 1010 | 1101 | 1011 | 1110 | 1110 | 1111 |
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.
- Convert the hex number to decimal: multiply each digit by its power of 16 and add the results.
- Divide the decimal number by 8 and write down the remainder.
- Divide the quotient by 8 again and write down the remainder.
- Repeat until the quotient is 0.
- 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.
| Hex | Binary | Octal | Decimal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| A | 1010 | 12 | 10 |
| B | 1011 | 13 | 11 |
| C | 1100 | 14 | 12 |
| D | 1101 | 15 | 13 |
| E | 1110 | 16 | 14 |
| F | 1111 | 17 | 15 |
The 3-bit patterns for octal digits are:
| Octal digit | 3 bits |
|---|---|
| 0 | 000 |
| 1 | 001 |
| 2 | 010 |
| 3 | 011 |
| 4 | 100 |
| 5 | 101 |
| 6 | 110 |
| 7 | 111 |
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.
| Octal | Hex | Symbolic | Typical use |
|---|---|---|---|
755 | 1ED | rwxr-xr-x | Programs and directories |
644 | 1A4 | rw-r--r-- | Ordinary files |
600 | 180 | rw------- | Private files such as SSH keys |
777 | 1FF | rwxrwxrwx | Open 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 755Bash 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
| Language | Method | Example | Result |
|---|---|---|---|
| Java | Integer.toOctalString() | Integer.toOctalString(0x1ED) | "755" |
| Excel | =HEX2OCT() | =HEX2OCT("1ED") | "755" |
| PHP | decoct(hexdec()) | decoct(hexdec('1ED')) | "755" |
| Swift | String(n, radix: 8) | String(0x1ED, radix: 8) | "755" |
Practice problems
Convert these values by hand, then check each answer with the converter above.
- 3C = 0011 1100 → 000 111 100 → 74₈.
- A0 = 1010 0000 → 010 100 000 → 240₈.
- 7FFF = 0111 1111 1111 1111 → 000 111 111 111 111 111 → 77777₈.
- C0FFEE = 1100 0000 1111 1111 1110 1110 → 110 000 001 111 111 111 101 110 → 60177756₈.
- Octal 154 = 001 101 100, which regroups as 0110 1100 → 6C₁₆.
- 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?
Is octal the same as hex?
When would you use octal instead of hex?
What is hex F in octal?
Why does the binary regrouping method work?
How many octal digits does a hex number need?
Can you convert hex to octal without binary?
What is 0o755 in hex?
Related tools
- Hex to decimal converter: convert hex to decimal with digit-by-digit steps.
- Decimal to hex converter: convert decimal to hex with the division method.
- Hex to binary converter: see the bit pattern of any hex value.
- Hex to text converter: decode hex bytes into ASCII or UTF-8 text.
- Hex to RGB converter: convert hex colour codes to RGB, HSL and HSV.