Excel functions / Math

DEC2HEX function

Writes a whole number in hexadecimal.

Syntax

=DEC2HEX(number, [places])

Arguments

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

  1. 255 in hexadecimal

    ABC
    1Number
    2255FF

    In C2: =DEC2HEX(A2) → FF

    Try this example

  2. A colour code from red, green and blue

    ABCDE
    1RedGreenBlue
    21512273#0F7A49

    In E2: ="#" & DEC2HEX(A2, 2) & DEC2HEX(B2, 2) & DEC2HEX(C2, 2) → #0F7A49

    Try this example

Common mistakes

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.

Translate a whole formula

Try DEC2HEX in the playground

Related functions