How to use DEC2HEX function in Excel?

The `DEC2HEX` function in Excel is used to convert a decimal number to its hexadecimal equivalent. Here’s how you can use it:

Syntax:

DEC2HEX(number, [places])
  • number: This is the decimal integer you want to convert to hexadecimal. It can be a negative or positive number.
  • places: This is an optional argument that specifies the number of characters for the resulting hexadecimal value. If the resulting hexadecimal value has fewer digits than specified by `places`, the function pads it with leading zeros. If this argument is omitted, Excel will use as many characters as necessary to represent the hexadecimal number.

Example Usage:

   =DEC2HEX(255)
  • Basic Conversion: To convert a decimal number to hexadecimal without specifying the number of characters:

This formula will return `FF`, which is the hexadecimal equivalent of the decimal number 255.

   =DEC2HEX(255, 4)
  • With Places Argument: To convert a decimal number to hexadecimal and specify the number of characters:

This will return `00FF`. The result is padded with zeros to ensure it is four characters long.

Important Notes:

  • The `number` must be an integer and can range from `-2^39` (-549,755,813,888) to `2^39-1` (549,755,813,887).
  • If the `number` is negative, the `places` argument is ignored, and the hexadecimal result is always 10 characters long, representing the 2’s complement binary format.
  • If the `places` argument is specified, it must be a positive integer. If it is a decimal, Excel will truncate it to an integer.
  • If there are not enough places specified to represent the number in hexadecimal, Excel will return a `#NUM!` error.

Using the `DEC2HEX` function can be particularly useful for tasks that involve working with computer memory addresses, color codes, or anywhere hexadecimal representation is required.

Unlock Your Potential

Excel

Basic - Advanced

Access

Access Basic - Advanced

Power BI

Power BI Basic - Advanced

Help us grow the project