OCT2HEX function
Converts an octal number to hexadecimal text, for example "100" to "40". Negative octal values give 10-digit hex results.
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
OCT2HEX(number, [places])| Argument | What it means | |
|---|---|---|
number | Required | The octal number to convert, as text or a number. At most 10 characters (30 bits): -536,870,912 to 536,870,911. A 10-character value whose first digit is the highest one is read as negative (two's complement). |
places | Optional | Minimum number of characters to return, padded with leading zeros. Ignored when the result is negative. |
Returns: Text containing the hexadecimal digits.
How OCT2HEX works
OCT2HEX converts from base 8 to base 16 in one step. It is useful when old documentation lists values in octal but newer tools expect hex, for example when migrating legacy device codes.
Inputs can have up to 10 octal digits. A 10-digit input starting with 4–7 is negative and the result is then 10 hex digits in two's complement (starting FFFFFFFF…). Positive results can be padded with places.
Examples
1Octal to hex
| A | B | |
|---|---|---|
| 1 | Octal | |
| 2 | 100 | 0040 |
Result: 0040
Octal 100 is 64 in decimal, which is 40 in hex. places = 4 pads it to 0040.
2Negative octal value
| A | B | |
|---|---|---|
| 1 | Octal | |
| 2 | 7777777533 | FFFFFFFF5B |
Result: FFFFFFFF5B
The input is -165 in octal two's complement; the hex equivalent of -165 in 40 bits is FFFFFFFF5B.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#NUM! | The input is not valid octal, is longer than 10 characters, or places is too small or negative. | Check for digits 8 and 9 and increase places. |
Tips
- The result is upper-case text. Use HEX2DEC if you need the number itself.
Google Sheets
OCT2HEX also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
OCT2HEX 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.
| Language | Function name |
|---|---|
| Danish | OKT.TIL.HEX |
| Dutch | OCT.N.HEX |
| Finnish | OKTHEKSA |
| French | OCTHEX |
| German | OKTINHEX |
| Hungarian | OKT.HEX |
| Italian | OCT.HEX |
| Norwegian (Bokmål) | OKTTILHEKS |
| Polish | ÓSM.NA.SZESN |
| Portuguese (Brazil) | OCTAHEX |
| Portuguese (Portugal) | OCTAHEX |
| Russian | ВОСЬМ.В.ШЕСТН |
| Spanish | OCT.A.HEX |
| Swedish | OKT.TILL.HEX |