Please note javascript is required for full website functionality.


A to Z of Excel Functions: The DEC2HEX Function

18 June 2018

The DEC2HEX function

This function converts a decimal number (base 10) to hexadecimal (base 16).

The DEC2HEX function employs the following syntax to operate:

DEC2HEX(number, [places])

The DEC2HEX function has the following arguments:

  • number: this is required and represents the decimal integer you want to convert. If number is negative, places is ignored and DEC2HEX returns a 10-character (40-bit) hexadecimal number in which the most significant bit is the sign bit. The remaining 39 bits are magnitude bits. Negative numbers are represented using two's-complement notation
  • places: this argument is optional. This is the number of characters to use. If places is omitted, DEC2HEX uses the minimum number of characters necessary. The argument places is useful for padding the return value with leading 0s (zeros).

Two's complement is a mathematical operation on binary numbers, as well as a binary signed number representation based on this operation. The two's complement of an N-bit number is defined as the complement with respect to 2N; in other words, it is the result of subtracting the number from 2N. This is also equivalent to taking the ones' complement and then adding one, since the sum of a number and its ones' complement is all 1 bits. The two's complement of a number behaves like the negative of the original number in most arithmetic, and positive and negative numbers can coexist in a natural way.

It should be further noted that:

  • if number is < -549,755,813,888 or if number is > 549,755,813,887, DEC2HEX returns the #NUM! error value
  • if number is non-numeric, DEC2HEX returns the #VALUE! error value
  • if the result of DEC2HEX requires more than the number of specified places characters, it returns the #NUM! error value. For example, DEC2HEX(64,1) returns the error value because the result (40) requires two characters
  • if places is not an integer, the value of places is truncated
  • if places is non-numeric, DEC2HEX returns the #VALUE! error value
  • if places is negative, DEC2HEX returns the #NUM! error value.

Please see my example below:

We’ll continue our A to Z of Excel Functions soon. Keep checking back – there’s a new blog post every business day.

A full page of the function articles can be found here.