Google Sheets OCT2HEX: Convert Octal to Hex

How-to basics · Updated November 23, 2026

The OCT2HEX function in Google Sheets converts a signed octal number (base 8) into a signed hexadecimal number (base 16). The syntax is OCT2HEX(signed_octal_number, [significant_digits]), where the first argument is required and the second is optional. For example, =OCT2HEX("777") returns 1FF.

What Is OCT2HEX Used For?

OCT2HEX is part of Google Sheets’ Engineering functions, which are designed for technical, scientific, and data-conversion tasks. It is most commonly used when you need to translate data from legacy systems, network configurations, or low-level programming contexts where octal numbers appear (e.g., Unix file permissions or certain assembly code) into hexadecimal, which is more compact and often easier to read for debugging. The function works entirely in the spreadsheet, so you can convert many values at once without manual calculation.

Unlike a simple base conversion, OCT2HEX respects the sign of the number. Octal numbers in this function are interpreted as signed 10-bit values (range -512 to 511) unless you specify more digits. This means that values above 377 (octal) will be treated as negative in the two’s complement sense, which is important for accurate conversions in engineering contexts.

How the OCT2HEX Function Works

The function takes one required argument and one optional argument:

  • signed_octal_number – the octal number you want to convert. This can be a string (e.g., "77") or a reference to a cell containing the octal number as text. It must be a valid octal number (digits 0–7) or the function returns an error.
  • significant_digits – (optional) the minimum number of hexadecimal digits you want in the result. If omitted, the function returns the minimal number of digits needed. If provided, the result is padded with leading zeros to that length, but only if the number is positive. For negative numbers, this argument is ignored.

The conversion follows two’s complement rules for signed numbers. In a 10-bit signed system, the highest positive octal value is 377 (which is 255 decimal, or FF in hex). Octal 400 represents -256 decimal, and octal 777 represents -1 decimal. The function automatically handles this sign interpretation.

Basic Examples and Syntax

Here are a few concrete examples to see how it works. Assume you have the following in cells A1:A4:

  • A1: "10" (octal 8 decimal)
  • A2: "777" (octal -1 decimal)
  • A3: "377" (octal 255 decimal)
  • A4: "400" (octal -256 decimal)

Enter these formulas in B1:B4:

  • =OCT2HEX(A1) returns 8
  • =OCT2HEX(A2) returns 1FF (because -1 in 10-bit two’s complement is 1FF in hex)
  • =OCT2HEX(A3) returns FF
  • =OCT2HEX(A4) returns 100 (because -256 in 10-bit is 100 in hex)

Notice that the function returns text strings, not numbers. This is because hexadecimal digits include letters (A–F), which cannot be stored as plain numbers. If you try to use the result in arithmetic, it will be treated as text unless you wrap it with VALUE() (but that only works for results that are purely numeric, like 8).

Using Significant Digits

The optional significant_digits argument lets you control the output length. For positive numbers, it pads the result with leading zeros. For example:

  • =OCT2HEX("10", 4) returns 0008
  • =OCT2HEX("377", 2) returns FF (no padding because it already has 2 digits)
  • =OCT2HEX("10", 1) returns 8 (no padding because it already has 1 digit)

If you specify a significant_digits value that is too small to hold the result, the function returns the minimal digits anyway (it does not truncate). For negative numbers, the argument is ignored entirely; the result always uses the 10-bit representation, which is 3 hex digits for the range -512 to -1 (e.g., 200 to 1FF).

If significant_digits is not a number, or is less than 1, the function returns an error. Also, if the octal number is not a valid octal string (e.g., contains an 8 or 9), you get a #NUM! error.

Common Errors and How to Fix Them

Here are the most frequent issues users run into with OCT2HEX:

  • #NUM! error – The octal number contains digits other than 0–7, or the number is outside the valid range (-512 to 511 decimal). Check that the input is a string with only octal digits.
  • #VALUE! error – The input is not a valid number or text. For example, if you reference a cell that contains a number like 10 (not text), Google Sheets may still accept it, but if it’s a date or boolean, it will fail.
  • Wrong sign interpretation – Users often expect 777 to be 511 decimal, but because it’s signed, it’s -1. If you need unsigned conversion, you can add a leading zero: OCT2HEX("0777") still returns 1FF because the leading zero doesn’t change the sign. To get the unsigned value, you’d need a workaround, like converting to decimal with OCT2DEC and then to hex with DEC2HEX (but that only works for positive numbers).
  • Result treated as text – If you try to use the result in a formula like =OCT2HEX("10")+1, it will fail because the result is text. Use VALUE() if you need a numeric value, but only for results that are purely digits (0–9).

OCT2HEX vs. Other Conversion Functions

Google Sheets offers a family of base-conversion functions: BIN2HEX, BIN2OCT, BIN2DEC, DEC2BIN, DEC2HEX, DEC2OCT, HEX2BIN, HEX2OCT, HEX2DEC, OCT2BIN, OCT2DEC, and OCT2HEX. They all follow the same pattern: the first argument is the number in the source base (as text or number), and the optional second argument is significant digits. The main difference is the target base and the sign handling.

If you need to convert from octal to decimal, use OCT2DEC. From octal to binary, use OCT2BIN. For the reverse (hex to octal), use HEX2OCT. These functions are all in the Engineering category under Insert > Function > Engineering.

In Microsoft Excel, the same functions exist, but they are part of the Analysis ToolPak add-in (which is usually enabled by default). The syntax is identical, so you can copy formulas between the two programs. However, Excel’s OCT2HEX also has a 10-bit signed limit, same as Google Sheets.

Practical Use Cases and Tips

Here are a few real-world scenarios where OCT2HEX comes in handy:

  • Unix file permissions – Octal numbers like 755 represent permissions. Converting to hex can help when you need to embed them in scripts or configuration files that expect hex.
  • Color codes – While colors are usually hex, sometimes you might have octal values from older systems. Convert them to hex to use in CSS or image editing.
  • Data cleaning – If you have a column of octal values imported from a legacy database, you can use OCT2HEX to standardize them to hex for easier processing.

One tip: always store octal numbers as text in your spreadsheet, especially if they have leading zeros (e.g., 0777). If you enter them as numbers, Google Sheets will drop the leading zero, and the conversion will still work, but you may lose formatting. To force text, you can prefix with an apostrophe ('0777) or use the TEXT function.

Frequently Asked Questions

Can OCT2HEX convert negative octal numbers? Yes, it handles negative numbers via two’s complement. For example, =OCT2HEX("777") returns 1FF, which is -1 in decimal. The sign is determined by the most significant bit in the 10-bit representation.

Why does my result have a leading zero? If you specify significant_digits, the function pads positive results with leading zeros to reach that length. For example, =OCT2HEX("10", 4) returns 0008. If you don’t want padding, omit the second argument.

What is the maximum octal number I can convert? The function works with signed 10-bit numbers, so the range is from 400 (which is -256 decimal) to 377 (which is 255 decimal). Any octal number outside this range returns a #NUM! error.

How do I convert an octal number to hex without the sign? If you need unsigned conversion, you can use a workaround: first convert to decimal with OCT2DEC (which treats the input as unsigned), then to hex with DEC2HEX. For example, =DEC2HEX(OCT2DEC("777")) returns 1FF as well, but for 400 it returns 100 (which is 256 decimal, not -256).

Does OCT2HEX work on mobile or in Excel? Yes, it works in the Google Sheets mobile apps and in Excel (with the Analysis ToolPak). The syntax is identical, so you can use the same formulas.

Why is my result showing as text? Because hexadecimal numbers contain letters, the function returns text. If you need a numeric value, use VALUE() on the result, but only if the result contains only digits (0–9). For example, =VALUE(OCT2HEX("10")) returns 8 as a number.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.