The DEC2HEX function in Microsoft Excel converts a decimal number to its hexadecimal equivalent. Here’s how it works:
Syntax:
DEC2HEX(number, [places])number: The decimal integer you want to convert. If the number is negative, theplacesargument is ignored, and DEC2HEX returns a 10-character (40-bit) hexadecimal number. The most significant bit represents the sign, and the remaining 39 bits represent magnitude (using two’s-complement notation for negative numbers).places(optional): The number of characters to use. If omitted, DEC2HEX uses the minimum necessary characters. It’s useful for padding the return value with leading zeros.
If
numberis less than -549,755,813,888 or greater than 549,755,813,887, DEC2HEX returns the#NUM!error value.If
numberis non-numeric, DEC2HEX returns the#VALUE!error value.If the result of DEC2HEX requires more characters than specified by
places, it returns the#NUM!error value. For example, DEC2HEX(64,1) returns an error because the result (40) requires two characters.If
placesis not an integer, its value is truncated. Ifplacesis negative, DEC2HEX returns the#NUM!error value.
Here are some examples:
- To convert decimal 100 to hexadecimal with 4 characters (padded with two leading zeros):
=DEC2HEX(100, 4)➡️ Result:0064 - To convert decimal -54:
=DEC2HEX(-54)➡️ Result:FFFFFFFCA - To convert decimal 28:
=DEC2HEX(28)➡️ Result:1C - Attempting to convert decimal 64 with only 1 character place:
=DEC2HEX(64,1)➡️ Result:#NUM!
Feel free to try it out in your Excel worksheet!


No comments:
Post a Comment