# How to use the DEC2HEX function

The DEC2HEX function converts a decimal number to a hexadecimal number.

##### What is a decimal number?

The decimal system is a positional numeral system that uses 10 as the base, it requires 10 different numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The dot or the decimal point represents decimal fractions which are not whole numbers.

The decimal number 520 has three positions, each with a different weight. It starts with 10^0 on the right and increases by one power on each additional position to the left.

520 = (**5***10^2)+(**2***10^1)+(**0***10^0)

520 = 500 + 20 + 0

##### What is a hexadecimal number?

A hexadecimal number is a number with a base of 16, for example, the decimal system uses a base of 10. This means that each digit in a hexadecimal number can have 16 possible values, from 0 to 15, however, the letters A to F are used from 10 to 15. See the hexadecimal column in the table below.

Hexadecimal numbers are often used in computers, the reason is they represent four binary digits (bits) with one hexadecimal digit. For example, the binary number 1010 is equivalent to the hexadecimal number A.

Hexadecimals make it easier to write big numbers with less digits, in other words, hexadecimals shorten binary digits considerably. For example, we can use hexadecimal to show the values of colors and MAC addresses in computers.

The following table shows the binary, decimal and hexadecimal values from 0 (zero) to 17.

Decimal |
Hexadecimal |

0 | 0 |

1 | 1 |

2 | 2 |

3 | 3 |

4 | 4 |

5 | 5 |

6 | 6 |

7 | 7 |

8 | 8 |

9 | 9 |

10 | A |

11 | B |

12 | C |

13 | D |

14 | E |

15 | F |

16 | 10 |

17 | 11 |

### Table of Contents

## 1. DEC2HEX function Syntax

DEC2HEX(*number*, *[places]*)

## 2. DEC2HEX function Arguments

number |
Required. The decimal integer you want to convert. |

[places] |
Optional. The number of characters to use. If not entered the function uses the number of characters needed to complete the task. This argument allows you to addÂ leading 0s (zeros). |

## 3. DEC2HEX function Example

The image above shows the DEC2HEX function in cells D3 an D4. It calculates the hexadecimal values based on the corresponding cells which contain different decimal numbers and [places].

Formula in cell D3:

The first cell B3 contains 9 and cell C3 contains the places number, the DEC2HEX function returns 00000009 in cell D3, the second cell B4 contains 15 and the DEC2HEX function returns 0000000F in cell D4.

The next section describes how these values are calculated in detail.

## 4. How is the DEC2HEX function calculated in detail?

There are different methods converting between decimal and hexadecimal, here is one way. Follow these steps to convert from decimal to hexadecimal:

- Divide the decimal number by 16 and write down the quotient and the remainder.
- Repeat the process with the quotient until it is zero. Make sure to note each quotient and remainder as you calculate each number.
- The hexadecimal number is the remainders from bottom to top.

For example, let us convert decimal number 199 to hexadecimal.

199/16 = 12 and remainder 7

12/16 = 0 and remainder 12 (B)

Decimal value 12 is hexadecimal value "B", see the conversion table above. The hexadecimal number is formed from the remainders counting from bottom to top. 199 = B7

## 5. DEC2HEX function not working

DEC2HEX returns the **#NUM!** error value if

*Number*is less than -549,755,813,888 or larger than 549,755,813,887. See cells B3 and C3 in the image above.- [places] is negative. See the formula next to cell C5.
- it requires more than the specified places characters. See the formula next to cell C6.

DEC2HEX returns the **#VALUE!** error if

- [places] is not a number. See the formula next to cell C7.
- The number is not a valid base 10 number. See cells B4 and C4 in the image above.

The second argument [places]is truncated if it is not an integer. For example, [places] is 4.1111111111 and the DEC2HEX function truncates it to 4. See the formula next to cell C8.

DEC2HEX ignores places and returns a 10-character hexadecimal number if the decimal number is negative.

### Useful resources

DEC2HEX function - Microsoft

Decimal to Hexadecimal converter

How to convert decimal to hexadecimal

### '' function examples

The following article has a formula that contains the function.

What's on this page Reverse text Insert random characters Convert letters to numbers How to shuffle characters in the alphabet […]

### Functions in 'Engineering' category

The DEC2HEX function function is one of 42 functions in the 'Engineering' category.

## How to comment

How to add a formula to your comment<code>Insert your formula here.</code>

Convert less than and larger than signsUse html character entities instead of less than and larger than signs.

< becomes < and > becomes >

How to add VBA code to your comment[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

How to add a picture to your comment:Upload picture to postimage.org or imgur

Paste image link to your comment.

Contact OscarYou can contact me through this contact form