Hexadecimal System

Hexadecimal System

The hexadecimal system has base 16 and is represented by the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}

Many values in computing are represented in hexadecimal

The value of a byte can be represented by two hexadecimal figures. From the decimal value 0 as 00, to the value 255 as FF

Every four binary figures correspond to a hexadecimal figure, so it also corresponds to the value of a nibble

Conversions

Convert from decimal number system to hexadecimal

The hexadecimal representation of a decimal number (the passage from a base 10 number to its corresponding on base 16) is calculated by successively dividing the ratio of the number division by divider 16, until a quotient less than 16 is obtained. The representation on base 16 will be, the last quotient followed by the last rest followed by the previous rest followed by the previous rest and thus up to the first remains obtained

To achieve the conversion, this table is also used to represent the values:

Conversion table
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

Example: Convert 3737 to hexadecimal representation

Number Ratio Rest
\frac{3737}{16} 233 9
\frac{233}{16} 14 9

14\rightarrow E
9\rightarrow 9

So we have to:

3737_{(10} = E99_{(16}

Convert from decimal number system to hexadecimal with decimal

The hexadecimal representation of a decimal number with decimal places (the passage from a base 10 number to its corresponding base 16), is calculated by multiplying the number (then the results) without its entire part by 16, to obtain a number without decimal places, up to a number that is repeated periodically (in the case of periodic numbers), or up to a number of digits predefined by machine accuracy. The base 16 representation will be, the whole part unchanged, then the comma is added and finally the whole part of the result of successive multiplications

Example: Convert 56.75 to hexadecimal representation with decimal places

Number Ratio Rest
\frac{56}{16} 3 8

3\rightarrow 3
8\rightarrow 8

So we have that the integer part is:

56_{(10} = 38_{(16}

Number Result Integer part
0,75 \cdot 16 12 12

12\rightarrow C

So we have that the decimal part is:

0,75_{(10} = C_{(16}

So we have to:

56,75_{(10} = 38,C_{(16}

To convert from hexadecimal system to decimal

The decimal representation of a binary number would correspond to applying the formula:

b_1 \cdot 16^{(n - 1)} + \cdots + b_n \cdot 16^0

Where n would be the length of the chain, \text{y }b_i the value corresponding to the i-th position of the string, starting from left to right

Example: Convert E99 to decimal representation

E\rightarrow 14
9\rightarrow 9

E99_{(16}=E \cdot 16^2 + 9 \cdot 16^1 + 9 \cdot 16^0 = 14 \cdot 256 + 9 \cdot 16 + 9 \cdot 1 = 3584 + 144 + 9 = 3737_{(10}

So we have to:

E99_{(16}=3737_{(10}

To convert from hexadecimal system to decimal with decimal places

If the number also has decimals, it will be expressed with the following formula:

b_1 \cdot 16^{(n - 1)} + \cdots + b_n \cdot 16^0 + b_{(n + 1)} * 16^{-1} + \cdots+ b_{(n + m)} \cdot 16^{-m}

Where n would be the length of the string without decimals, m the length of the string with decimals, b_i the value corresponding to the i-th position of the string, starting from left to right

Example: Convert 38.C to decimal representation

3\rightarrow 14
8\rightarrow 9
C\rightarrow 12

38,C_{(16}=3 \cdot 16^1 + 8 \cdot 16^0 + C \cdot 16^{-1} = 3 \cdot 16 + 8 \cdot 1 + 12 \cdot 0,0625 = 48 + 8 + 0,75 = 56,75_{(10}

So we have to:

38,C_{(16}=56,75_{(10}