Skip to content
Hexadecimal Converter

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.

Method: Through binary: three bits to four
Write each octal digit as 3 bits
Octal digitBits
7111
5101
5101
Regroup in 4s from the point outward (pad: 3 zeros on the left)
GroupHex digit
00011
1110E
1101D

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.

  1. Write each octal digit as exactly three bits, 0 = 000 through 7 = 111.
  2. Join the bits in order.
  3. Starting from the right, split them into groups of four and pad the leftmost group with zeros.
  4. 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

Write each octal digit as 3 bits
Octal digitBits
7111
5101
5101
Regroup in 4s from the point outward (pad: 3 zeros on the left)
GroupHex digit
00011
1110E
1101D

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.

The number 493 as an octal and a hex literal
LanguageOctalHexNote
C, C++, Java07550x1EDa bare leading zero means octal
Python 30o7550x1ED0755 is a syntax error
JavaScript0o7550x1ED0755 only in sloppy mode
Go0o755 or 07550x1EDboth forms accepted
Rust0o7550x1ED0755 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.

Last updated