DEC2HEX Function

DEC2HEX Function

DEC2HEX Function

Convert decimal numbers to hexadecimal text in Excel. Useful for memory addresses, color values, and any workflow that needs compact base-16 output.

ExcelClash Team
PUBLISHED

Summary

DEC2HEX converts a decimal number into hexadecimal text. If you start with a normal base-10 value and need a base-16 result like FF or 0400, this is the function to use.

It comes up a lot in technical work because hex is shorter and easier to read than long binary strings. It is also common in memory addresses, register values, and color codes, so DEC2HEX is a simple way to move between the numbers people usually type and the format systems often display.

Purpose

Convert decimal to hex

Turns a base-10 number into base-16 text.

Return value

Hex text

Returns text made of 0-9 and A-F.

Syntax

=DEC2HEX(number, [places])

number is the decimal value to convert. places is optional and pads the result with leading zeros when you need a fixed width.

The result is hexadecimal text, not a numeric hex type. If you need a short display such as FF, you can use the formula with just the number. If you need a fixed-width result such as 00FF, add places.

Arguments

  • number - [required] The decimal integer to convert. Excel supports values from -549,755,813,888 to 549,755,813,887.
  • [places] - [optional] The minimum number of characters to return for positive values.

number must be a whole number in Excel's supported range for this function. places is optional and only affects positive values. It is useful when the workbook needs a consistent text width for codes, addresses, or exported output. Negative values ignore places and return the signed 10-character format.

DEC2HEX vs similar functions

DEC2HEX is best when you already have a decimal number and want a hex string back:

Function What it does Typical use Result
DEC2HEX Converts decimal to hexadecimal Addresses, IDs, color channels Hex text
HEX2DEC Converts hexadecimal to decimal Turn hex back into a number for math Number
DEC2BIN Converts decimal to binary Bit patterns and flags Binary text
DEC2OCT Converts decimal to octal Legacy or Unix-style workflows Octal text

Using DEC2HEX

The most common use is formatting. If a worksheet stores values as decimal but a report or system expects hex, DEC2HEX gives you that translation directly. A value like 1024 becomes 400, and if you want a fixed-width result you can ask for 0400 instead.

The places argument matters only for positive numbers. It pads the result with zeros on the left, which is useful for codes, addresses, and display formats where every value should have the same length. If the converted result is longer than the places value, Excel returns #NUM!.

Negative numbers work differently. Excel returns them as 10-character hexadecimal values and ignores the places argument. That behavior follows the signed format these engineering conversion functions use, so results like FFFFFFFFFF are expected for -1.

Example 1 - Convert 255 to hex

This is the standard decimal-to-hex conversion pattern. Excel returns FF, which is a common reference point because it shows the maximum value that fits in one unsigned byte. The example is simple, but it gives a clear sense of how DEC2HEX compresses a familiar decimal number into base-16 form.

=DEC2HEX(255) // Returns "FF"
Check Answer
Challenge #1
Target: Sheet1!F1
Basic Hex Conversion

Convert Decimal 255 to hexadecimal. Formula: =DEC2HEX(255).

Example 2 - Pad the result to 4 characters

Padding matters when the hex output has to match a field width used by addresses, codes, or exported text formats. The decimal value 1024 becomes 400 naturally, but with 4 places Excel returns 0400, preserving the same value in a format that aligns cleanly with other fixed-width results.

=DEC2HEX(1024, 4) // Returns "0400"
Check Answer
Challenge #2
Target: Sheet1!F2
Memory Address Padding

Convert 1024 to a 4-character padded hex string. Formula: =DEC2HEX(1024, 4).

Example 3 - Convert a negative value

Negative decimal values do not simply gain a minus sign in the hex output. Instead, Excel returns a signed 10-character engineering-format result. Here, -1 becomes FFFFFFFFFF, which is the representation you need to recognize when working with signed technical values.

=DEC2HEX(-1) // Returns "FFFFFFFFFF"
Check Answer
Challenge #3
Target: Sheet1!F3
Negative Signed Hex

Convert -1 to 10-character hexadecimal (40-bit). Formula: =DEC2HEX(-1).

Example 4 - Build a color byte

This example shows a practical formatting use outside low-level engineering data. An RGB channel is often stored as a two-character hex byte, so converting 165 to A5 makes the value ready for color-code style output without any extra text manipulation.

=DEC2HEX(165, 2) // Returns "A5"
Check Answer
Challenge #4
Target: Sheet1!F4
RGB Color Generator

Convert color component 165 to 2-digit hex. Formula: =DEC2HEX(165, 2).

Quick recap

  • Converts decimal to hex: DEC2HEX returns base-16 text from a base-10 number.
  • Places pads positive values: Use it when you need leading zeros.
  • Negative values ignore places: Excel returns them as 10-character signed hex values.
  • Returns text: Use HEX2DEC if you need to convert the result back into a number.
  • Useful for addresses and color work: It is a practical formatting function, not just an academic conversion tool.
Tactical Arena
Select Scenario:
Share DEC2HEX Function!

Tell your friends about this post

Discussion

ExcelClash is an interactive platform designed to level up your Excel skills through real-world exercises and challenges. Sharpen your logic, solve real spreadsheet problems, and learn faster.

© 2026 ExcelClash, Inc. All rights reserved.