OCT2HEX in Google Sheets: Repack Octal Fields into Hexadecimal
Convert octal text to hexadecimal in Google Sheets, regroup bits rather than replacing digits and verify signed negative representations and field widths.
Verification status: See the evidence and test scope described in this guide. How formula examples are checked
Quick answer: OCT2HEX(signed_octal_number,[significant_digits]) converts signed octal text to hexadecimal. Octal digits encode three bits each, while hexadecimal digits encode four, so conversion requires regrouping the quantity.
Availability and version history
- Introduced: first introduction date is not established by the reviewed official history; no desktop release number is inferred.
- Availability: documented in the rolling Google Sheets service; these examples use the web worksheet workflow.
- Checked: October 14, 2026; official OCT2HEX reference. Documentation and independent models, with no native Sheets execution or wider client certification.
Syntax and signed input range
=OCT2HEX(signed_octal_number,[significant_digits])
Google specifies thirty-bit signed octal input, with 3777777777 as the positive endpoint and 4000000000 as the negative endpoint. Their decimal meanings are 536870911 and −536870912.
Valid numeric digit inputs are converted to their string form. For example, numeric 177 and text “177” both denote octal 177 and yield hex 7F, representing 127. Numeric 177 is not interpreted as the decimal quantity 177 in this function.
The optional width pads a nonnegative output with leading zeros. Too few positions produces documented #NUM!; a negative signed input ignores the width. The dedicated page does not establish fractional-width truncation or every invalid-argument combination.
Example 1: convert a fixed-width octal file
Format A2:A6 as Plain text and enter only the first column. In B2 use =OCT2HEX(A2,4) and fill down. The decimal check is explanatory, not a separate pasted input column.
| A, octal | B, hex output | Decimal check |
|---|---|---|
| 011 | 0009 | 9 |
| 052 | 002A | 42 |
| 134 | 005C | 92 |
| 245 | 00A5 | 165 |
| 552 | 016A | 362 |
For 552, the octal digit groups become binary 101 101 010. Regroup from the right into four-bit groups: 0001 0110 1010. These yield hexadecimal 16A, padded to 016A by the requested width.
Copying the visible digits 552 into a hexadecimal field would instead represent 5×256+5×16+2=1362. That is a different quantity. Conversion is not a character substitution table applied separately to each octal digit.
Example 2: preserve full negative representations
| Formula | Expected hexadecimal |
|---|---|
=OCT2HEX("7777777773",4) |
FFFFFFFFFB |
=OCT2HEX("7777777726",4) |
FFFFFFFFD6 |
=OCT2HEX("4000000000",4) |
FFE0000000 |
The quantities are −5, −42 and −536870912. The expected ten-position hex outputs follow the forty-bit two’s-complement model documented by HEX2DEC.
For −42, the unsigned forty-bit encoding is 2^40−42=1099511627734. Its hex digits are FFFFFFFFD6. This model explains sign extension from the thirty-bit input format to the wider hexadecimal representation.
A valid width of four does not shorten these negatives. In contrast, short octal 726 means positive 470 and converts to hex 1D6. Removing the leading sign-extension digits before conversion changes the signed meaning.
Advanced example: verify the quantity independently
With the first fixture, put =OCT2DEC(A2) in C2 and =HEX2DEC(B2) in D2, filling both down. Both columns return 9, 42, 92, 165 and 362. In E2 use =C2=D2; all five comparisons are TRUE.
For a negative check, =OCT2DEC("7777777726") and =HEX2DEC("FFFFFFFFD6") both represent −42. A decimal decoder must use the correct base and signed width; reading either digit string as an ordinary decimal number is not that check.
OCT2DEC is useful when imported text needs a quantity column for totals, comparisons or numeric validation.
Advanced example: reverse the representation with an explicit width
Enter =HEX2OCT(B2,3) in F2 and fill down. Expected results are 011, 052, 134, 245 and 552. This reverse conversion recovers the original three-position fixture because that width is supplied explicitly.
If the original text had been 000011 instead, the same reverse formula would still give 011. The numeric quantity does not retain an arbitrary original character count. Keep original strings or field-length metadata when exact file reconstruction matters.
HEX2OCT has its own target-range restriction. The values here fit; validity in one converter is not universal admission to every other base converter.
Calculate before encoding and check errors
The first two fixture quantities total 51. =DEC2HEX(OCT2DEC(A2)+OCT2DEC(A3),4) returns 0033. The result contains only decimal-looking digits, but its quantity is hexadecimal 33, or decimal 51.
Ordinary arithmetic on 0033 would treat it as decimal 33. Decode labels before calculations and encode only when producing the desired output representation.
=OCT2HEX("128",4) contains an invalid octal digit and follows Google’s documented #NUM! rule. =OCT2HEX("552",2) requires three hex positions and also follows the too-small-width rule. General coercion, extreme-width limits and native error precedence remain untested.
References and verification
Examples use fictional data, English function names and comma separators. Expected outputs are independent mathematical calculations or explicitly documented rules, not native Sheets captures. Check the spreadsheet locale when reproducing punctuation-sensitive formulas.