Octal to Hex Converter
To convert octal to hex, write each octal digit as three bits, regroup the bits in fours from the right, and read each group as one hex digit. For example, 755 is 111 101 101 in binary; regrouped as 0001 1110 1101 it reads 1ED. Both equal 493 in decimal.
Repeats forever:
Repeats forever:
Method: Through binary: three bits to four
| Octal digit | Bits |
|---|---|
| 7 | 111 |
| 5 | 101 |
| 5 | 101 |
| Group | Hex digit |
|---|---|
| 0001 | 1 |
| 1110 | E |
| 1101 | D |
Result: 1ED.
How to convert octal to hex by hand
Octal is older than hex as a programmer’s shorthand. It suited machines with 12-, 18- and 36-bit words, which divide evenly by three. Moving a value to hex means re-cutting the same bits on four-bit boundaries.
- Write each octal digit as exactly three bits, 0 = 000 through 7 = 111.
- Join the bits in order.
- Starting from the right, split them into groups of four and pad the leftmost group with zeros.
- Read each group as one hex digit and drop a leading 0 if one appears.
Watch the width when the octal value has a leading zero meant as a prefix, as in 0755. The converter treats that zero as an octal marker and says so under the panel, and 0o is removed the same way.
Worked example: 755
Nine bits, regrouped into fours
7558 = 1ED16 = 49310
| Octal digit | Bits |
|---|---|
| 7 | 111 |
| 5 | 101 |
| 5 | 101 |
| Group | Hex digit |
|---|---|
| 0001 | 1 |
| 1110 | E |
| 1101 | D |
Result: 1ED.
How languages write octal and hex literals
The leading-zero convention from C has caused real bugs: a table of zero-padded numbers such as 010, 020, 030 silently means 8, 16 and 24. Newer languages either require the explicit 0o prefix or treat the bare zero as decimal. Hex has been 0x almost everywhere.
When you copy a mode or a constant between languages, convert the literal rather than the digits: a Python 0o755 pasted into C needs to become 0755 or 0x1ED.
| Language | Octal | Hex | Note |
|---|---|---|---|
| C, C++, Java | 0755 | 0x1ED | a bare leading zero means octal |
| Python 3 | 0o755 | 0x1ED | 0755 is a syntax error |
| JavaScript | 0o755 | 0x1ED | 0755 only in sloppy mode |
| Go | 0o755 or 0755 | 0x1ED | both forms accepted |
| Rust | 0o755 | 0x1ED | 0755 is decimal 755 |
Octal and hex escapes name the same byte
In C string literals, \101 is an octal escape and \x41 a hex one, and both are the byte 65, the letter A. Shells, Perl and many config formats accept the same pair. Converting between them is this page’s method applied to a single byte: 101 is 001 000 001, regrouped as 0100 0001, which is 41.
Octal escapes take up to three digits and stop at the first non-octal character, while hex escapes in C keep consuming hex digits, so "\x41BC" is not A followed by BC. When in doubt, prefer the octal form or split the string.
Questions people ask
What is 755 octal in hex?
1ED. 755 is 111 101 101 in binary; regrouped in fours from the right as 1 1110 1101 it reads 1, E, D. Both are 493 in decimal.
What does the leading zero in 0755 mean?
In C, C++ and Java a leading 0 marks an octal literal, so 0755 means 493. Python 3 rejects 0755 and requires 0o755, and JavaScript accepts 0755 only outside strict mode; 0o755 works in both.
What is \101 in hex?
\101 is an octal escape for 65, the letter A. The same byte as a hex escape is \x41: octal 101 is 001 000 001 in binary, regrouped as 0100 0001, which is 41.
What is 777 octal in hex?
1FF. 777 is nine ones in binary; grouped from the right as 1 1111 1111 it reads 1FF, which is 511 in decimal.
Related conversions
Last updated