Excel functions / Math
DEC2HEX function
Writes a whole number in hexadecimal.
Syntax
=DEC2HEX(number, [places])
Arguments
number: A whole number.places(optional): Pad with zeros on the left to this many digits.
When to use it
DEC2HEX writes a whole number in hexadecimal (base 16), as text using 0 to 9 and A to F. Colour codes are three hexadecimal pairs, which makes it handy for building them.
Examples
255 in hexadecimal
A B C 1 Number 2 255 FF In C2:
=DEC2HEX(A2)→ FFA colour code from red, green and blue
A B C D E 1 Red Green Blue 2 15 122 73 #0F7A49 In E2:
="#" & DEC2HEX(A2, 2) & DEC2HEX(B2, 2) & DEC2HEX(C2, 2)→ #0F7A49
Common mistakes
- Padding. Without the second argument, 15 is "F", not "0F". Give 2 for colour codes.
DEC2HEX in other languages
Excel shows function names in its own language. In these languages it also puts a semicolon between arguments where English has a comma.
- Czech: DEC2HEX
- Danish: DEC.TIL.HEX
- Dutch: DEC.N.HEX
- Finnish: DESHEKSA
- French: DECHEX
- German: DEZINHEX
- Hungarian: DEC.HEX
- Italian: DECIMALE.HEX
- Norwegian: DESTILHEKS
- Polish: DZIES.NA.SZESN
- Portuguese (Brazil): DECAHEX
- Portuguese (Portugal): DECAHEX
- Russian: ДЕС.В.ШЕСТН
- Spanish: DEC.A.HEX
- Swedish: DEC.TILL.HEX
- Turkish: DEC2HEX