# Documentation/Calc Functions/HEX2DEC

Jump to navigation Jump to search

HEX2DEC

Add-in

## Summary:

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

HEX2DEC(Number)

## Returns:

Returns an integer number in the range -239d < 239, which is the decimal value that corresponds to the specified hexadecimal number.

## Arguments:

Number is a string or a number, or a reference to a cell containing one of those types, which gives the hexadecimal number that is to be converted to decimal. The hexadecimal number must comprise no more than 10 characters and should correspond to a decimal number in the range -239d < 239. If the hexadecimal number contains any letters (a…f or A…F; the case of these characters is not significant), it must either be in a referenced cell or passed as a string argument in quotation marks.

• Number should use the standard two's complement representation. In two's complement, positive numbers are hexadecimal 0 to 7FFFFFFFF (0 to 239-1 decimal) and negative numbers are hexadecimal FFFFFFFFFF to 8000000000 (-1 to -239 decimal). Negative numbers must be ten digits long with the leftmost digit set to 1; positive numbers can comprise less than 10 digits.
• If Number does not specify a valid hexadecimal number, then HEX2DEC reports an invalid argument error (Err:502). This may arise, for example, if Number contains more than 10 characters or if it contains any character other than 0…9, a…f, or A…F.
• If a hexadecimal value containing one or more letters is passed directly to the function and is not surrounded by quotation marks, HEX2DEC reports a #NAME? error.
• If Number is a string comprising no characters, or a reference to an empty cell, HEX2DEC returns 0.
• Although the content of Number may appear to be decimal if it contains no letters, HEX2DEC will interpret it correctly.

## Additional details:

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

## Examples:

Formula Description Returns
=HEX2DEC("1D") Here the function converts the hexadecimal value of 1D (passed as a string) to its decimal equivalent of 29. 29
=HEX2DEC(1D) Here the function returns an invalid name error because Calc does not recognize 1D as a number. #NAME?
=HEX2DEC(15) Here the function converts the hexadecimal value of 15 (passed as a number) to its decimal equivalent of 21. 21
=HEX2DEC(D1) where cell D1 contains 1D (text). Here the function again converts the hexadecimal value of 1D to its decimal equivalent of 29. 29
=HEX2DEC("8000000000") Here the function converts the minimum allowed 10-character hexadecimal value of 8000000000 to its decimal equivalent of -549755813888 (equal to -239). -549755813888
=HEX2DEC("FFFFFFFFFF") Here the function converts the 10-character hexadecimal value of FFFFFFFFFF to its decimal equivalent of -1. -1
=HEX2DEC("7fffffffff") Here the function converts the hexadecimal value of 7fffffffff to its decimal equivalent of 549755813887 (equal to 239-1). 549755813887

HEX2DEC