DEC2HEX function

DEC2HEX converts decimal numbers to hexadecimal text format, useful for encoding inventory IDs or converting numeric values for data interchange.

=DEC2HEX(number, [places])

Generate a DEC2HEX formula

Describe what you need. The generator will reach for DEC2HEX where DEC2HEX is the right tool, and tell you when it is not.

How to get a better answer
  • Name your columns by letter and by header: "column F (Net Value)" beats "the amount column".
  • State every condition, including the negatives — "not cancelled" changes the formula's shape.
  • Say where the data starts if it is not row 1, and whether it will grow.
  • Check the settings above match your spreadsheet: the wrong argument separator is a syntax error on your machine.

Arguments

How DEC2HEX reads its arguments
numberrequiredplacesoptionalDEC2HEX
ArgumentRequiredDescription
numberRequiredA decimal integer between 0 and 281474976710655; negative numbers and decimals return #NUM!.
placesOptionalOptional; specifies output string length, padding with leading zeros if needed; omit for minimum width, use only non-negative integers.

Returns

A text string representing the hexadecimal equivalent of the input decimal number.

Availability

Excel: All · Google Sheets: Supported

Worked examples

1. Convert inventory quantity to hexadecimal code

SKUWarehouseOn HandReorder PointCost
SKU001A25610015.5
SKU002B51220022.75
SKU003A102430018
SKU004C204850012.5
=DEC2HEX(B2)

Result: 100

The on-hand quantity for SKU001 is 256 units. DEC2HEX converts this to its hexadecimal equivalent, 100. This is useful for creating compact inventory codes or encoding SKU data.

2. Convert reorder point to fixed-width hexadecimal

SKUWarehouseOn HandReorder PointCost
SKU001A25610015.5
SKU002B51220022.75
SKU003A102430018
SKU004C204850012.5
=DEC2HEX(D3,4)

Result: 012C

The reorder point for SKU003 is 300. DEC2HEX(300,4) pads the result to 4 characters, producing 012C. Fixed-width hex codes ensure consistent field lengths for database records or barcode systems.

3. Encode product cost as hexadecimal

SKUWarehouseOn HandReorder PointCost
SKU001A25610015.5
SKU002B51220022.75
SKU003A102430018
SKU004C204850012.5
=DEC2HEX(INT(E2*100),3)

Result: 60E

SKU001's cost is $15.50. Multiplying by 100 converts to cents (1550), and DEC2HEX(1550,3) with 3-character padding produces 60E. This lets you encode price data in hex format for compact storage or system integration.

Common errors

Which DEC2HEX error are you seeing?
DEC2HEX returned an error#NUM!
Ensure your input is a non-negative integer within range. For large values, break them into smaller components before converting.
#NUM!
Use only non-negative whole numbers for places. Omit the argument if you don't need padding.
#VALUE!
Verify both arguments are numeric. If referencing cells, ensure they contain only numbers, not formulas that return text.
ErrorWhy it happensHow to fix it
#NUM!The number argument is negative or exceeds 281474976710655 (the maximum 48-bit unsigned integer).Ensure your input is a non-negative integer within range. For large values, break them into smaller components before converting.
#NUM!The places argument is negative or not an integer.Use only non-negative whole numbers for places. Omit the argument if you don't need padding.
#VALUE!Either the number or places argument is not a valid numeric value or contains text that cannot be coerced to a number.Verify both arguments are numeric. If referencing cells, ensure they contain only numbers, not formulas that return text.

Tips and when to use something else

  • DEC2HEX always returns text, not a number, even though the result looks numeric. If you need to perform arithmetic on the result, use VALUE() to convert it back.
  • The maximum value DEC2HEX can handle is 281474976710655 (2^48 - 1). For larger numbers, consider breaking your calculation into chunks and concatenating hex results.
  • Use HEX2DEC to reverse the process—convert hexadecimal text back to decimal. This is essential when reading hex codes from external systems.
  • For simple base conversion in data pipelines, CONVERT may be simpler; reserve DEC2HEX for cases where you specifically need hexadecimal output for encoding or ID generation.

Frequently asked questions

Why does DEC2HEX return text instead of a number?
Hexadecimal values often represent codes or identifiers (like serial numbers or color codes) where leading zeros matter. Text preserves those zeros; numeric format would drop them. Use VALUE(DEC2HEX(...)) only if you need to do arithmetic on the result.
How does DEC2HEX handle negative numbers?
It returns two's complement notation using all ten hexadecimal characters, so DEC2HEX(-5) gives FFFFFFFFFB rather than -5. That is correct but surprising if you expected a minus sign, and the places argument is ignored for negative input because the result is always ten characters. The accepted range is -549,755,813,888 to 549,755,813,887; anything outside it returns #NUM!.
What's the difference between DEC2HEX and CONVERT?
CONVERT is designed for unit conversion (meters to feet, etc.) and doesn't have a hex output option. DEC2HEX is the dedicated function for decimal-to-hexadecimal conversion and provides the places parameter for fixed-width padding.
Can I use DEC2HEX on decimal numbers with fractional parts?
No; DEC2HEX only accepts integers. If your input has decimals, use INT() or ROUND() first to convert to a whole number. For example, =DEC2HEX(INT(18.75)) returns 12.

Need a different formula?

The full generator is not scoped to one function — describe any spreadsheet problem and it will pick.

Open the formula generator

Reviewed 2026-09-17