In the dataset below, we have some positive and negative decimal numbers. Let’s convert them to hexadecimal using 2 different methods.
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)
- 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))
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.
- 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)
- 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!