Quick Navigation
DEC2HEX Function
Summary
The DEC2HEX function converts decimal numbers to their hexadecimal representation. It handles both positive and negative integers, with special two's-complement notation for negatives, making it essential for binary data analysis, programming, and low-level computing tasks.
Syntax
DEC2HEX(number, [places])
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| number | Number |
Yes | Decimal integer to convert to hexadecimal. Negative values use two's-complement notation with 40-bit output. |
| places | Number |
No | Number of characters in result. Omitting uses minimum needed; useful for zero-padding. |
Using the DEC2HEX Function
DEC2HEX is invaluable for programmers, hardware engineers, and data analysts working with binary representations. Use it to display memory addresses, color codes, register values, or any scenario requiring hexadecimal output from decimal inputs.
Common DEC2HEX Examples
Padding with Leading Zeros
=DEC2HEX(100, 4)
Converts 100 to '0064' - pads with leading zeros to 4 characters.
Negative Number Conversion
=DEC2HEX(-54)
Converts -54 to 'FFFFFFFFCA' using 40-bit two's complement notation.
Simple Positive Conversion
=DEC2HEX(28)
Converts 28 directly to '1C' without padding.
Error Case - Insufficient Places
=DEC2HEX(64,1)
Returns #NUM! error since '40' requires 2 characters but only 1 place specified.
Frequently Asked Questions
Common Errors and Solutions
#NUM!
Cause: Number out of valid range (-549,755,813,888 to 549,755,813,887)
Solution: Ensure input is within 40-bit signed integer limits
#NUM!
Cause: Result requires more characters than specified places
Solution: Increase places parameter or omit it
#VALUE!
Cause: Non-numeric input
Solution: Provide valid decimal number
#NUM!
Cause: Negative places value
Solution: Use zero or positive integer for places
Notes
- Valid range: -549,755,813,888 to 549,755,813,887 (40-bit signed)
- Negatives always return 10 characters regardless of places
- Places truncates decimals (3.9 becomes 3)
- Perfect companion to HEX2DEC for round-trip conversions
Compatibility
Available in: Excel 2007, Excel 2010, Excel 2013, Excel 2016, Excel 2019, Excel 2021, Microsoft 365
Not available in: Excel 2003 and earlier
Content last reviewed: December 9, 2025
Update frequency: As needed
Excel versions tested: Excel 2007+