How do you convert octal to hex?
Expand each octal digit into three bits, then regroup those bits in fours from the right and read off hex digits. Octal 1234 becomes 001 010 011 100, regrouped as 0010 1001 1100, which is 29c in hex. Binary is the bridge because both bases are powers of two: 8 is 2³ and 16 is 2⁴.
You can also go through decimal (multiply out by powers of 8, then divide by 16), but the bit route needs no arithmetic beyond two small lookup tables.
Using the converter
- Type the octal number.
0755and755are equivalent. - Click Convert.
- Copy the hex result, which comes out in lowercase with no
0x:1ed.
Worked example: 1234
| Stage | Value |
|---|---|
| Octal digits | 1 · 2 · 3 · 4 |
| Each as 3 bits | 001 · 010 · 011 · 100 |
| Joined | 001010011100 |
| Regrouped in 4s from the right | 0010 · 1001 · 1100 |
| Hex digits | 2 · 9 · c |
| Result | 29c |
To double-check, both sides equal 668 in decimal: 1 × 512 + 2 × 64 + 3 × 8 + 4 = 668, and 2 × 256 + 9 × 16 + 12 = 668.
Git file modes in hex
Git records every entry in a tree object with an octal mode. The git fast-import documentation lists the valid ones: 100644 for a normal file, 100755 for an executable, 120000 for a symlink, 160000 for a gitlink (submodule) and 040000 for a subdirectory. When you inspect packed objects, index files or other tools' binary output, those same values appear in hex:
| Git mode (octal) | Hex | Entry type |
|---|---|---|
100644 |
81a4 |
regular file |
100755 |
81ed |
executable file |
120000 |
a000 |
symbolic link |
160000 |
e000 |
submodule (gitlink) |
040000 |
4000 |
directory |
Paste any of the octal modes into the tool to reproduce the right-hand column. The pattern is easy to see once you have it: the low 9 bits hold the permissions (644 is 1a4, 755 is 1ed) and the high bits hold the entry type.
Mistakes that cause errors
- Using 8 or 9.
789is not octal. If you meant decimal, use the decimal to hex converter. - Adding a prefix.
0o755fails becauseoisn't a digit. A plain leading zero is fine. - Spaces between digits.
7 5 5fails. Outer whitespace is trimmed, inner whitespace isn't. - Signs and points.
-17and7.5aren't supported; the tool converts non-negative whole numbers only. - Values over 53 bits. Octal
400000000000000000is 2^53, one past the safe limit, so it's refused instead of rounded.
Handy reference values
| Octal | Hex | Note |
|---|---|---|
7 |
7 |
single digits 0 to 7 are the same in both |
10 |
8 |
octal 10 means eight |
17 |
f |
fifteen |
377 |
ff |
one full byte |
777 |
1ff |
nine bits all set (rwxrwxrwx) |
17777777777 |
7fffffff |
largest signed 32-bit integer |
Doing it in a terminal or script
If you're already at a shell, printf '%x\n' 0755 prints 1ed. The leading zero matters there: the POSIX printf utility reads numeric arguments the way C reads integer constants, so 0755 is octal while 755 would be taken as decimal and print 2f3. In Python, write the octal literal explicitly and call hex(0o755), which returns '0x1ed'. The converter here avoids that ambiguity entirely, because it always reads your input as octal, with or without the leading zero.
Where to go next
The site doesn't have separate octal-to-decimal or octal-to-binary tools, but you can chain: convert here, then feed the hex into hex to decimal or hex to binary. For the reverse trip, hex to octal converts back, and decimal to octal is the place to start when your file mode was printed as a plain decimal number.
Last updated