Contact

OCT2HEX in Excel: Convert Octal Codes and Extend Negative Values

Engineering Intermediate Microsoft Excel

Convert octal text to hexadecimal in Excel, preserve padded fields and verify signed thirty-bit to forty-bit negative representations.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Quick answer: OCT2HEX(number,[places]) converts octal notation to hexadecimal. Nonnegative results can be padded; negative thirty-bit octal values become ten-character hexadecimal representations that preserve their signed quantity.

Availability and version history

  • Introduced: the first introduction version is not established by the reviewed official history.
  • Availability: official help lists Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel 2024, Excel 2021, Excel 2021 for Mac, Excel 2019, Excel 2019 for Mac, Excel 2016. This reference lists Excel 2019 for Mac but omits Excel 2024 for Mac; the omission is not filled from another function.
  • Checked: October 14, 2026; official OCT2HEX reference. Documentation and independent models; no native Excel execution or wider platform certification.

Syntax and two signed formats

=OCT2HEX(number,[places])

The input permits at most ten octal characters, or thirty bits, with two’s-complement interpretation. Microsoft documents #NUM! for invalid octal input.

Places is optional. Omission uses the minimum necessary nonnegative output width. Too few places produces #NUM!, fractional places is truncated, nonnumeric places produces #VALUE!, and negative places produces #NUM!. The reference does not separately establish zero places or every excessive-length error detail.

For a negative quantity, places is ignored and the output contains ten hexadecimal characters, representing forty bits. This is sign extension to a wider representation, not an unsigned reinterpretation of the original digits. The source’s function-specific Mac-version list is preserved in the availability section.

Example 1: convert a fixed-width octal column

Format A2:A6 as Text and enter these representations. Use =OCT2HEX(A2) in B2 and =OCT2HEX(A2,4) in C2, filling down.

Only the first table column is input data. The Decimal check column is explanatory and is not pasted into B; put calculated outputs in the worksheet cells specified above.

Octal Decimal check Minimum hex Width 4
12 10 A 000A
55 45 2D 002D
145 101 65 0065
360 240 F0 00F0
640 416 1A0 01A0

Octal 640 gives 6×64+4×8=416. Hex 1A0 gives 1×256+10×16=416. The two positional calculations independently agree.

In D2 use =OCT2DEC(A2) and in E2 use =HEX2DEC(C2), then fill down. Both columns return 10, 45, 101, 240 and 416. The base changes, while the quantity stays the same.

Example 2: inspect negative sign extension

Octal input Signed quantity Expected hexadecimal
7777777777 -1 FFFFFFFFFF
7777777770 -8 FFFFFFFFF8
7777777533 -165 FFFFFFFF5B
4000000000 -536870912 FFE0000000

The −165 row is also a documented Microsoft control. Its thirty-bit unsigned encoding is 2^30−165, while the forty-bit hex encoding is 2^40−165. Both must be interpreted with their own sign widths.

If 7777777777 were treated as an unsigned octal quantity, it would be 1073741823 and hex 3FFFFFFF. OCT2HEX instead recognizes the signed input as −1 and returns FFFFFFFFFF. That distinction is essential when converting an external file.

A supplied valid width such as 4 does not shorten the negative result. Do not use places as if it selected an arbitrary signed-byte format.

Advanced example: verify a mixed-sign conversion pipeline

Enter octal strings 145, 7777777770 and 4000000000 in G2:G4 as Text. In H2 use =OCT2HEX(G2) and fill down. The expected outputs are 65, FFFFFFFFF8 and FFE0000000.

In I2 use =OCT2DEC(G2) and in J2 use =HEX2DEC(H2), then fill down. Both numeric columns return 101, −8 and −536870912. OCT2DEC and HEX2DEC provide the independent signed-decoding checks.

A reverse HEX2OCT conversion can preserve these quantities because they fit its narrower target interval. It does not restore the original character width unless that width is explicitly retained or supplied where appropriate.

Advanced check: group positive bits between bases

Octal 145 has binary groups 001 100 101. For hexadecimal grouping, pad that positive representation on the left as 0000 0110 0101, giving 065 or minimal 65.

This explains why three-bit octal groups and four-bit hex groups do not align digit by digit. Replacing each octal digit with a hex digit of the same character would leave 145, which is hexadecimal 325 rather than decimal 101.

The grouping exercise is deliberately positive. Negative full-width conversion must preserve the signed quantity through the correct sign extension, as shown above.

Errors and reliable use

=OCT2HEX("640",2) needs three hex positions and follows the documented insufficient-width #NUM! rule. Places 4.9 is truncated to 4 and produces 01A0. An input such as 89 is not valid octal and follows the documented invalid-digit condition.

Use DEC2HEX when the source column already contains decimal quantities. Keep base labels and original strings beside converted output, especially when leading zeros or signed widths are part of an import specification.

Native prefix acceptance, whitespace cleanup and unspecified argument-error precedence remain untested. The expected strings and decoded quantities are independent positional and two’s-complement calculations within the documented format.

References and verification

Expected outputs are independently calculated examples or documented rules, not captured native Excel results. Formulas use English function names and comma argument separators. Locale, rendering and boundary restrictions are stated where relevant.