# Documentation/Calc Functions/DEC2HEX

Jump to navigation Jump to search

DEC2HEX

Add-in

## Summary:

Converts a decimal number (base-10) to its hexadecimal (base-16) equivalent. The input decimal number must be in the range -239d < 239-1.

## Syntax:

DEC2HEX(Number[; Places])

## Returns:

Returns a text string comprising up to 10 hexadecimal characters (0…9 or A…F), which is the hexadecimal number in two’s complement form that corresponds to the specified decimal number.

## Arguments:

Number is a string or a number, or a reference to a cell containing one of those types, which gives the decimal number that is to be converted to hexadecimal. Number should be an integer value that is not less than -239 or greater than 239-1.

Places is an integer in the range 1 to 10, or a reference to a cell containing that value, which is the number of hexadecimal characters that should be returned for a positive Number. Places is ignored for negative values of Number, when DEC2HEX always returns 10 hexadecimal characters. The default for positive values of Number is for the returned string to occupy as many characters as necessary to accommodate the hexadecimal representation; however, you can set the value of Places to add leading zeroes where necessary.

• If Number is non-numeric (including an empty string), then DEC2HEX reports a #VALUE! error.
• If Number is a non-integer value, then DEC2HEX truncates it to an integer.
• If, after any truncation, Number is outside the range specified, DEC2HEX reports an invalid argument error (Err:502).
• If Number is a reference to an empty cell, DEC2HEX returns 0 (possibly with leading zeroes, depending on the value of Places).
• If Places is non-numeric, then DEC2HEX reports an invalid argument error (Err:502).
• If Places is a non-integer value, then DEC2HEX truncates it to an integer.
• If, after any truncation, Places is less than 1 or greater than 10, DEC2HEX reports an invalid argument error (Err:502).
• If Number is positive and Places is less than the minimum number of characters required to accommodate the hexadecimal representation of Number, then DEC2HEX reports an invalid argument error (Err:502).

## Additional details:

The following Wikipedia pages provide useful background information relevant to this function:

## Examples:

Formula Description Returns
=DEC2HEX(63) Here the function converts the decimal value of 63 (passed as a number) to its hexadecimal equivalent of 3F. 3F
=DEC2HEX("63"; 4) Here the function again converts the decimal value of 63 (passed as a string) to its hexadecimal equivalent of 3F but also adds two leading zeroes. 003F
=DEC2HEX(D1; D2) where cells D1 and D2 contain the numbers 63 and 6 respectively. Here the function again converts the decimal value of 63 (passed via a cell reference on this occasion) to its hexadecimal equivalent of 3F but also adds four leading zeroes. 00003F
=DEC2HEX(-POWER(2; 39)) Here the function converts the minimum allowed decimal value of -239 to its hexadecimal equivalent of 8000000000. 8000000000
=DEC2HEX(-1) Here the function converts the decimal value of -1 to its hexadecimal equivalent of FFFFFFFFFF. FFFFFFFFFF
=DEC2HEX(POWER(2; 39)-1) Here the function converts the maximum allowed decimal value of 239-1 to its hexadecimal equivalent of 7FFFFFFFFF. 7FFFFFFFFF

DEC2HEX