How to Convert Decimal Number to Hexadecimal (Hex) in Excel

In the dataset below, we have some positive and negative decimal numbers. Let’s convert them to hexadecimal using 2 different methods.

excel decimal to hex


Method 1 – Using Excel DEC2HEX Function

Excel has a built-in function to convert a decimal number to its hexadecimal format called DEC2HEX.

Steps:

  • Make a column to store the hexadecimal numbers and enter the following formula in its first cell, here cell C5:

=DEC2HEX(B5)

Using Excel DEC2HEX Function to Convert Decimal to Hex (Hexadecimal)

  • Press ENTER.

  • Use the Fill Handle to AutoFill the cells below.

The hexadecimal numbers are returned.


Method 2 – Using the Colon

In some databases, the digits of a hexadecimal number need to be separated by colon symbols when the numbers are very large.

Steps:

  • Make a column to store the hexadecimal numbers and enter the following formula in cell C5:

=IF(MOD(LEN(DEC2HEX(B5)),2)=1,"0"&MID(DEC2HEX(B5),1,1)&":"&MID(DEC2HEX(B5),2,2)&":"&MID(DEC2HEX(B5),4,2)&":"&MID(DEC2HEX(B5),6,2)&":"&MID(DEC2HEX(B5),8,2),MID(DEC2HEX(B5),1,2)&":"&MID(DEC2HEX(B5),3,2)&":"&MID(DEC2HEX(B5),5,2)&":"&MID(DEC2HEX(B5),7,2)&":"&MID(DEC2HEX(B5),9,2))

Converting Decimal to Hexadecimal with Colon

The formula uses the IF, MOD, LEN, and MID functions to insert colons inside the hexadecimal number, then DEC2HEX to convert this string to hexadecimal.

  • Press ENTER.

The decimal number in B5 is converted to a hexadecimal number.

excel decimal to hex method 2

  • Drag the Fill Handle to AutoFill the cells below.

The large decimal numbers are converted to hexadecimal numbers (hex) with colons.


How to Convert Decimal Number to Other Number Formats

We can convert the decimals to other formats like binary and octal using similar formulas with the DEC2BIN and DEC2OCT functions. As their names suggest, the DEC2BIN and DEC2OCT functions convert a decimal number to its binary and octal formats.

Steps:

  • Store your decimal numbers in a column and enter the following formula into the first cell of the adjacent column, here cell C5:

=DEC2BIN(B5)

excel decimal to hex

  • Use the Fill Handle to AutoFill the cells below.

The decimal data is converted to binary format.

  • To convert the numbers to octal format, use the formula given below:

=DEC2OCT(B5)

  • And fill the cells below using the Fill Handle.


Things to Remember

  • For the DEC2HEX function, the range of numbers that can be converted is [-2^39, 2^39 – 1] or [-549,755,813,888, 549,755,813,887]. If we insert any decimal number out of this range, the formula will return the Number (#NUM!) error.
  • Similarly, the applicable number range for DEC2BIN and DEC2OCT functions are [-512,511] and [-536,870,912, 536,870,911].

Download Practice Workbook


<< Go Back to | Excel Number System Conversion | Excel for Math | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Meraz Al Nahian
Meraz Al Nahian

Md. Meraz Al Nahian has worked with the ExcelDemy project for over 1.5 years. He wrote 140+ articles for ExcelDemy. He also solved a lot of user problems and worked on dashboards. He is interested in data analysis, advanced Excel, statistics, and dashboards. He also likes to explore various Excel and VBA applications. He completed his graduation in Electrical & Electronic Engineering from Bangladesh University of Engineering & Technology (BUET). He enjoys exploring Excel-related features to gain efficiency... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo