HEX2OCT Function (LibreOffice Calc)
Learn the HEX2OCT function in LibreOffice Calc: Converts a hexadecimal number to an octal number.
Verification status: Selected examples were executed in LibreOffice Calc 25.2.3.2. This does not establish that every formula and edge case was tested. How formula examples are checked
Quick answer: convert hexadecimal to octal
HEX2OCT converts a signed hexadecimal value into an octal text string. For example, =HEX2OCT("6A";4) returns 0152: hexadecimal 6A means decimal 106, or octal 152, padded to four characters. Its optional second argument specifies the minimum output width for nonnegative values, not the number base. This is an engineering / analysis add-in function. LibreOffice Help โ analysis functions (checked 2026-10-11; section HEX2OCT).
Syntax and arguments
HEX2OCT(Number [; Places])
Number โ Required. Hexadecimal text consisting of 0โ9 and AโF, up to 10 hexadecimal characters. Upper/lowercase are interchangeable in the native examples. A cell containing a text code is recommended to preserve leading zeroes. This is a signed, 40-bit two’s-complement input; the octal result has a tighter 30-bit signed range.
Places โ Optional. Requested minimum number of octal characters for nonnegative results. Omitted: no unnecessary leading zeros. Insufficient, zero or negative width produced Err:502 in tested Calc 25.2. For a negative value, width was ignored and 10 octal digits were returned.
Separators and regional settings: In the English-language Calc environment tested, function arguments are separated with ;, as in =HEX2OCT("F";3). Excel and many Google Sheets locales use commas instead. Decimal notation also depends on locale; examples assume English (.) numeric punctuation. Places is not a base argument. A fractional width of 3.9 was truncated to 3 by Calc 25.2 in one native test; use whole-number widths for portable formulas.
Version scope: Syntax and examples were checked against the currently served LibreOffice 26.8 Help and executed in Calc 25.2.3.2 on 2026-10-11 (the included test workbook). The exact original introduction version, alternative UI-localized function names, and runtime behaviour in LibreOffice 26.8 were not independently tested. The ODS test workbook stores formulas with the of:=HEX2OCT(...) OpenFormula prefix; this is an observed serialization, not a claim about all file formats.
Reproducible examples (tested in LibreOffice Calc 25.2.3.2)
On a narrow screen, scroll this table sideways to see every column.
| Input and formula | Expected and observed result | Why |
|---|---|---|
=HEX2OCT("6a";4) |
text 0152 |
Official Help example: hex 6A โ decimal 106 โ octal 152, padded. |
=HEX2OCT("F";3) |
text 017 |
Hex F is 15 decimal and 17 octal. |
=HEX2OCT("FF") |
text 377 |
No Places: shortest result. |
=HEX2OCT("0";4) |
text 0000 |
Leading zeros are meaningful to the display but not arithmetic. |
=HEX2OCT("a5") |
text 245 |
Lowercase input works. |
=HEX2OCT("FFFFFFFFFF") |
text 7777777777 |
Signed 40-bit hexadecimal -1, expressed in ten octal digits. |
=HEX2OCT("FFFFFFFF00") |
text 7777777400 |
Signed -256. |
=HEX2OCT("FFFFFFFFFF";1) |
text 7777777777 |
Negative results ignore width. |
To reproduce the cell-reference example: enter 6A as text in A2 (format cell as Text first, or type an initial apostrophe). In B2 enter:
=HEX2OCT(A2;4)
The expected and observed B2 result is 0152 (text). You can fill the formula down beside a column of hexadecimal source codes. Do not multiply the resulting 0152 by 8 or treat it as decimal 152.
Practical workflow: normalize hexadecimal IDs into fixed-width octal codes
On a narrow screen, scroll this table sideways to see every column.
| Cell | Content | Type |
|---|---|---|
A2 |
6A |
Hexadecimal source text |
A3 |
FF |
Hexadecimal source text |
A4 |
0 |
Hexadecimal source text |
B2 |
=HEX2OCT(A2;4) |
Calculated code |
B3 |
=HEX2OCT(A3;4) |
Calculated code |
B4 |
=HEX2OCT(A4;4) |
Calculated code |
Expected results in B2:B4: 0152, 0377, 0000 (these three outputs follow directly from native-tested individual formulas; the fill-down table as laid out above was not separately asserted). This can help when joining older octal-only data exports to hexadecimal register dumps; carry both the source code and the converted code in separate columns. For error isolation, =IFERROR(HEX2OCT("G1");"Invalid hex") was natively tested and returned Invalid hex.
Advanced: signed limits and safe numeric comparisons
Hexadecimal source values use up to 40 bits, but octal conversion is restricted to the signed 30-bit result. The source code 1FFFFFFF converts to the greatest accepted positive result, 3777777777; FFE0000000 converts to the minimum signed result, 4000000000. These boundary formulas both passed native tests. Conversely, =HEX2OCT("20000000") and =HEX2OCT("FFDFFFFFFF") produced Err:502 in Calc 25.2 even though both inputs consist only of legal hexadecimal digits. Do not confuse valid characters with a convertible numeric range. Microsoft and Google document the corresponding positive/negative range for their implementations too.
To compare numbers arithmetically, convert the octal string back to decimal, rather than comparing its characters. For instance:
=OCT2DEC(HEX2OCT("6A"))
Expected and observed numeric result: 106. This round-trip test was executed natively. Another tested end-to-end conversion is =HEX2OCT(DEC2HEX(-100)), returning ten-character text 7777777634.
Errors, unusual inputs, and troubleshooting
On a narrow screen, scroll this table sideways to see every column.
| Symptom | Typical reason | What to check |
|---|---|---|
Err:502 |
Invalid hex characters | =HEX2OCT("ZZ") produced Err:502; restrict codes to hexadecimal 0โ9, AโF before converting. |
Err:502 |
More than 10 hex characters | =HEX2OCT("FFFFFFFFFFF") produced Err:502; count characters, not digits in decimal notation. |
Err:502 |
Too narrow a Places value |
=HEX2OCT("6A";2) needs 3 octal characters and produced Err:502. Use 3 or more. |
Err:502 |
Zero or negative width | =HEX2OCT("F";0) and =HEX2OCT("F";-1) produced Err:502. |
Err:502 |
Out-of-range signed value | =HEX2OCT("20000000") failed though syntax and characters were valid. |
Err:502 |
Adding a 0x prefix |
=HEX2OCT("0xFF") produced Err:502; enter FF, without a prefix. |
| Leading zeroes seem lost | Treating the result as a number | Keep code outputs as text and avoid VALUE or arithmetic coercion. |
| Different output in Excel/Sheets | Locales and error representation differ | Use , rather than ; if that application requires it, and check the documented width limits. |
Unexpected behaviour observed: Numeric literal 199 was treated as hexadecimal characters by HEX2OCT(199) and returned text 631 (hex 199 = decimal 409 = octal 631). Do not assume the literal is already a decimal integer to be converted. Prefer "199" or text-formatted cell inputs. Invalid-input outcomes above are native observations in Calc 25.2.3.2, not predictions for every program/version.
Compatibility and interoperability
- LibreOffice Calc: The current Help lists
HEX2OCTamong analysis add-in functions; the examples and boundary cases noted above were natively executed in 25.2.3.2. - Microsoft Excel: Its HEX2OCT help documents
HEX2OCT(number, [places]), 10-character signed input, leading-zero padding and#NUM!for several invalid numeric inputs. Excel was not executed during this run. - Google Sheets: Its HEX2OCT help documents the corresponding signed conversion and warns that treating the octal output as an ordinary decimal numeral can mislead arithmetic. Sheets was not executed.
- Other spreadsheet engines: Not verified. Do not assume the same function exists or has identical error codes.
This is distinct from DEC2OCT, which takes a decimal input rather than a hexadecimal string; HEX2DEC produces an ordinary numeric result; and OCT2HEX reverses the code conversion. Saved ODS tests are included in the separate review package, but compatibility on XLSX import/export has not been tested.
Related LibreOffice guides
Official sources and testing evidence
- LibreOffice 26.8 Help โ Analysis functions Part One,
HEX2OCTsection, accessed 2026-10-11: function purpose, official argument order, 10-character hexadecimal input, signed two’s-complement support, optionalPlaces, worked6aexample. The Help page labels itself 26.8; Calc 26.8 runtime was not tested. - Microsoft Excel HEX2OCT reference, accessed 2026-10-11: 30-bit octal range restriction, optional width, application-specific error types.
- Google Sheets HEX2OCT reference, accessed 2026-10-11: 40-bit input, 30-bit signed octal range, text/arithmetic warning.
- Native test record:
research/native-results.jsonand the savedresearch/LibreOffice_HEX_Conversion_Tests.odsfrom this batch; cases with names prefixedoct_and matching error observations were executed in LibreOffice Calc 25.2.3.2 through UNO. The test script isresearch/run_native.py; no formulas were run in Excel or Sheets. The earlier test log is retained with the release audit.
How this guide was checked
Selected example formulas were run in LibreOffice Calc 25.2.3.2 on Linux on October 12, 2026. The official Help may cover a newer version. Tests of selected formulas do not certify every locale, interactive array operation or file round trip. View the example-check record.