How to convert hex or binary to a number
✓ Verified in LibreOffice 25.8.7.3Read a hexadecimal, binary, or octal string back into a normal decimal number you can do math on — parsing color codes, register values, or bit flags.
The formula
| App | Formula | Notes |
|---|---|---|
| Excel | =HEX2DEC(A2) | HEX2DEC for hexadecimal, BIN2DEC for binary, OCT2DEC for octal. The result is a real number you can calculate with. |
| Google Sheets | =HEX2DEC(A2) | Identical. All three *2DEC functions exist in Sheets. |
| LibreOffice Calc | =HEX2DEC(A2) | Identical. |
How it works
The *2DEC family is the inverse of the DEC2* converters: HEX2DEC("FF") returns 255, BIN2DEC("1010") returns 10, and OCT2DEC("17") returns 15. Unlike the DEC2* outputs, these return actual numbers, so you can add, compare, or format them straight away. The input can be a text string or an unquoted value, but note hexadecimal that starts with a letter (like "FF" or "A1") must be text or it will be read as a cell reference. For very large hex values beyond the ~10-digit limit, or to convert from an arbitrary base, use DECIMAL(text, radix) which handles bases 2 to 36. To convert directly between two non-decimal bases skip the round-trip and use functions like HEX2BIN or BIN2HEX. Going the other way — a number into a hex or binary string — is DEC2HEX / DEC2BIN (see convert-a-number-to-hex-or-binary).
Verified, not just documented
We ran =HEX2DEC("FF") in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 255 — exactly the expected result. Every formula here is confirmed by actually executing it.
Functions used
HEX2DEC — see full Excel, Google Sheets & LibreOffice compatibility for each.