Before going through the methodology of converting a decimal number into a hexadecimal number, read the article Numbers Representation Systems – Decimal, Binary, Octal and Hexadecimal. It will help you understand which are the main used number representation systems and what a hexadecimal number is.
Let’s start by writing down the first five powers of 16 (we’ll use them in our conversion example):
\[ \begin{split}16^0 &= 1 \\
16^1 &= 16 \\
16^2 &= 256 \\
16^3 &= 4096 \\
16^4 &= 65535
\end{split} \]
As example, we are going to convert the decimal number 6959 into a hexadecimal number.
Step 1. Divide 6959 to the closest lower power of 16 (in our case is 4096).
\[6959 : 4096 = 1 \quad \text{(remainder 2863)}\]Step 2. Take the remainder from the previous step and divide again to the closest lower power of 16.
\[2863 : 256 = 11 \quad \text{(remainder 47)}\]Step 3. Take the remainder from the previous step and divide again to the closest lower power of 16.
\[47 : 16 = 2 \quad \text{(remainder 15)}\]Step 4. Take the remainder from the previous step and divide again to the closest lower power of 16.
\[15 : 1 = 15 \quad \text{(remainder 0)}\]We stop dividing when the remainder is 0. We now take all the quotients (results of the divisions) and write their hexadecimal notation:
\[ \begin{split}1 &\rightarrow 1 \\
11 &\rightarrow B \\
2 &\rightarrow 2 \\
15 &\rightarrow F
\end{split} \]
The result is the converted hexadecimal number: 1B2F. So the decimal number 6959 (base 10) is equivalent with the hexadecimal number 1B2F (base 16).
\[\bbox[#FFFF9D]{6959_{10}=\text{1B2F}_{16}}\]A common notation for hexadecimal numbers, is to use the prefix 0x in the front of the number. This is useful to distinguish from decimal numbers, when using symbols from 0 to 9. For example, 1275 in hexadecimal is different from 1275 in decimal. Therefore we write the hexadecimal number as 0x1275.
For fast and easy decimal to hexadecimal conversions, we can use the Scilab function dec2hex()
.
--> dec2hex(6959)
ans =
1B2F
-->
For any questions, observations and queries regarding this article, use the comment form below.
Don’t forget to Like, Share and Subscribe!