Engineering

DEC2HEX Function in Excel

Converts a decimal number to hexadecimal.

Syntax

  • =DEC2HEX(number, [places])

Arguments

  • number (required): Decimal number
  • places (optional): Number of characters to use

Examples

  • =DEC2HEX(255, 4) - Decimal to hex - Result: 00FF

DEC2HEX in technical sheets

  • Document units in adjacent cells — many engineering functions require exact unit strings.
  • Use [CONVERT](/functions/convert/) for unit changes before specialized formulas.
  • Validate inputs with [ISNUMBER](/functions/isnumber/) and range checks.

Common errors

  • #NUM! if out of range

Use cases

  • Color codes
  • Memory addresses
  • Programming

Frequently asked questions

  • How do I convert RGB colors to hex codes? Concatenate DEC2HEX for each color: ="#"&DEC2HEX(R,2)&DEC2HEX(G,2)&DEC2HEX(B,2). For RGB(255, 128, 0): ="#"&DEC2HEX(255,2)&DEC2HEX(128,2)&DEC2HEX(0,2) = "#FF8000" (orange).
  • What is the places parameter for? Places pads the result with leading zeros. DEC2HEX(15) = "F", but DEC2HEX(15, 2) = "0F". Useful for consistent formatting like color codes where you always want 2 digits per component.
  • What is the range limit for DEC2HEX? DEC2HEX handles -549,755,813,888 to 549,755,813,887. For larger numbers, use a custom formula or Power Query. Negative numbers return 10-character two's complement representation.

Editorial review

  • Reviewed by Excel.Directory Editorial Team. Updated May 2026.