HEX2DEC function
Converts hexadecimal text such as "FF" or "1A3F" to a decimal number. A 10-digit value starting with 8–F is read as negative.
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
HEX2DEC(number)| Argument | What it means | |
|---|---|---|
number | Required | The hexadecimal number to convert, as text or a number. At most 10 characters (40 bits): -549,755,813,888 to 549,755,813,887. A 10-character value whose first digit is the highest one is read as negative (two's complement). |
Returns: A decimal number (which can be negative).
How HEX2DEC works
HEX2DEC turns a hexadecimal value into an ordinary decimal number you can calculate with. Typical uses: splitting a web colour code into its red, green and blue values, reading error codes and register dumps, converting memory addresses, or turning Unicode code points into numbers for UNICHAR.
The input is up to 10 hex characters, in upper or lower case. Hex digits A to F stand for 10 to 15. When the input is exactly 10 characters and its first digit is 8 or higher, Excel treats it as a negative number in 40-bit two's complement — FFFFFFFFFF is -1. Shorter inputs are always positive, so FFFFFFFF (8 characters) is 4,294,967,295.
The result is a real number, so you can add, compare and format it. Inputs longer than 10 characters or containing anything other than 0–9 and A–F (such as a # or 0x prefix) return #NUM!; strip those first. For values longer than 10 digits use DECIMAL.
Examples
1Convert hex to decimal
| A | B | |
|---|---|---|
| 1 | Hex | |
| 2 | FF | 255 |
Result: 255
F is 15, so FF = 15×16 + 15 = 255.
2Get the red channel from a colour code
| A | B | |
|---|---|---|
| 1 | Colour | |
| 2 | 1E90FF | 30 |
Result: 30
MID picks the first two characters, 1E, and HEX2DEC turns them into 30. Use MID(A2,3,2) and MID(A2,5,2) for green (144) and blue (255). If the code starts with #, start one character later or remove it with SUBSTITUTE.
3A negative value in two's complement
| A | B | |
|---|---|---|
| 1 | Hex | |
| 2 | FFFFFFFF9C | -100 |
Result: -100
Ten characters starting with F means the sign bit is set, so the result is negative: 2^40 − 100 is read back as -100.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#NUM! | The input is more than 10 characters, or contains characters that are not hex digits (for example #, 0x, spaces). | Strip prefixes with =HEX2DEC(SUBSTITUTE(A2,"#","")) or RIGHT(A2, LEN(A2)-2) for 0x; use DECIMAL for long values. |
Tips
- Lower-case input is fine:
=HEX2DEC("ff")also returns 255. - To turn a Unicode code point like
U+20ACinto the character, use=UNICHAR(HEX2DEC(MID(A2,3,10))). - A 10-character hex value that starts with the top digit is negative in two's complement. If you meant a large positive number, it does not fit — use DECIMAL and BASE instead, which work up to 2^53.
- A hex value that looks like a number in scientific notation, such as
1E5, may be converted by Excel when typed. Format the column as Text before typing or pasting hex codes.
Questions
Why does HEX2DEC return a negative number for FFFFFFFFFF?
Ten hex characters starting with 8–F are read as a 40-bit two's-complement negative number. Use DECIMAL(A2,16) if you need the unsigned value.
How do I convert a hex code with 0x in front?
Remove the prefix first: =HEX2DEC(MID(A2,3,10)).
Google Sheets
HEX2DEC also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
HEX2DEC 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 | HEX.TIL.DEC |
| Dutch | HEX.N.DEC |
| Finnish | HEKSADES |
| French | HEXDEC |
| German | HEXINDEZ |
| Hungarian | HEX.DEC |
| Italian | HEX.DECIMALE |
| Norwegian (Bokmål) | HEKSTILDES |
| Polish | SZESN.NA.DZIES |
| Portuguese (Brazil) | HEXADEC |
| Portuguese (Portugal) | HEXADEC |
| Russian | ШЕСТН.В.ДЕС |
| Spanish | HEX.A.DEC |
| Swedish | HEX.TILL.DEC |