DEC2HEX


Converts a decimal number to hexadecimal.

Syntax:

DEC2HEX(number, numdigits)


returns a hexadecimal number as text, given the decimal number, which must be between -239 and 239-1 inclusive, and may be text or a number.

The output is a hexadecimal number with up to ten digits in two's complement representation.numdigits is an optional number specifying the number of digits to return.

Example:

DEC2HEX(30)

returns 1E as text.

DEC2HEX("30")

returns 1E as text. DEC2HEX will accept a decimal number given as text.

DEC2HEX(30, 4)

returns 001E as text. Leading zeroes are added to make 4 digits.

DEC2HEX(-2)

returns FFFFFFFFFE as text.


Application:

Converting RGB Color Codes


In web design, colors are often represented using hexadecimal codes, where each pair of characters (from 00 to FF) corresponds to the intensity of red, green, and blue (RGB). The decimal values for red, green, and blue can range from 0 to 255. To get the correct hexadecimal color code, you need to convert each decimal value to its hexadecimal equivalent and then concatenate them.


Let's say a web designer wants to find the hexadecimal code for a specific shade of purple, which has the following decimal RGB values:

  • Red: 128
  • Green: 0
  • Blue: 128


Here’s how the DEC2HEX function would be used in an Excel spreadsheet to perform this conversion.


Scenario: A web designer is creating a color palette and has a list of decimal RGB values that need to be converted to hexadecimal codes.

Decimal Value

DEC2HEX Formula

Hexadecimal Value

A
B
C
1

Red: 128

DEC2HEX(128, 2)
80
2

Green: 0

DEC2HEX(0, 2)
00
3

Blue: 128

DEC2HEX(128, 2)
80

Explanation of the Formula:

  • DEC2HEX(128, 2):
    • 128: This is the decimal number you want to convert.
    • 2: This is the optional places argument. It ensures that the result is padded with leading zeros to a specific number of characters. In this case, 2 is used because each hexadecimal component of an RGB code is two characters long (e.g., 00, 0A, FF). Without this argument, DEC2HEX(0) would return 0, not 00, which would be incorrect for a hex color code.


Result:

By converting each decimal value and then concatenating the results, the web designer gets the final hexadecimal color code: #800080. This code can now be used in CSS or HTML to apply the correct shade of purple to a web page element.





This page is protected by Google reCAPTCHA. Privacy - Terms.
 
Built using Zapof