Engineering function

HEX2OCT function

Converts a hexadecimal number to octal text, for example "F" to "17". Works for values from -536,870,912 to 536,870,911.

Available in Excel 2007 and later (Excel 2003 needed the Analysis ToolPak add-in), Microsoft 365, Excel for the web, Excel for Mac

Excel 2007 and laterWorks in Google Sheets

Syntax

HEX2OCT(number, [places])
ArgumentWhat it means
numberRequiredThe hexadecimal number to convert, as text or a number. At most 10 characters (40 bits): -549,755,813,888 to 549,755,813,887. A 10-character value whose first digit is the highest one is read as negative (two's complement).
placesOptionalMinimum number of characters to return, padded with leading zeros. Ignored when the result is negative.

Returns: Text containing the octal digits.

How HEX2OCT works

HEX2OCT converts directly from base 16 to base 8. It is equivalent to DEC2OCT(HEX2DEC(number)), but in one step and with the same two's-complement rules for negative numbers.

Positive inputs must not exceed 1FFFFFFF (536,870,911), because the octal result is limited to 30 bits. Negative inputs are 10 hex digits from FFE0000000 to FFFFFFFFFF; they produce 10-digit octal results. places pads positive results with zeros and is ignored for negative ones.

Examples

1Hex to octal with padding

B2fx=HEX2OCT(A2, 3)
AB
1Hex
2F017

Result: 017

F is 15 = 1×8 + 7, which is 17 in octal; places = 3 gives 017.

2A negative value

B2fx=HEX2OCT(A2)
AB
1Hex
2FFFFFFFF007777777400

Result: 7777777400

The input is -256 in 40-bit two's complement. Excel converts it to -256 in 30-bit octal two's complement: 7777777400.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 13 KB

Common errors and how to fix them

ErrorWhy it happensFix
#NUM!The input is not valid hex, is longer than 10 characters, the value does not fit in 30 bits, or places is too small.Check the range and characters; use HEX2DEC and BASE for larger values.

Tips

  • Hex input can be upper or lower case.
  • If you get #NUM! for a large positive hex value, the octal result would need more than 10 digits; use =BASE(HEX2DEC(A2),8).

Google Sheets

HEX2OCT also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

HEX2OCT in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
DanishHEX.TIL.OKT
DutchHEX.N.OCT
FinnishHEKSAOKT
FrenchHEXOCT
GermanHEXINOKT
HungarianHEX.OKT
ItalianHEX.OCT
Norwegian (Bokmål)HEKSTILOKT
PolishSZESN.NA.ÓSM
Portuguese (Brazil)HEXAOCT
Portuguese (Portugal)HEXAOCT
RussianШЕСТН.В.ВОСЬМ
SpanishHEX.A.OCT
SwedishHEX.TILL.OKT