ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 19.08.2020
Просмотров: 888
Скачиваний: 3
|
Place |
4 |
3 |
2 |
1 |
0 |
|
Exponential value of the place |
164 |
163 |
162 |
161 |
160 |
|
Decimal value of the place |
65,536 |
4096 |
256 |
16 |
1 |
Table 4 Exponential and decimal values corresponding to a digit's place in a number
There are two methods for converting hexadecimal into decimal. There is the direct approach using the formula:
p(b)p + dp-1(b)p-1 + . . . + d0(b)0
Where dp is the digit in the highest place in the number, and dp-1 is the next highest place in the number, and so on. b is the base and p is the value of the highest place.
The conversion is as follows:
4 × 163 + A × 162 + 3 × 161 + F × 160 =4 × 4096 + 10 × 256 + 3 × 16 + 15 × 1 =16,384 + 2560 + 48 + 15 =19,007
This method is particularly useful for larger hexadecimal numbers. However, for smaller numbers of one or two digits, it is often faster to convert the hexadecimal number to binary before converting it to decimal. Hexadecimal maintains a relationship with binary as it is a derivative of a base2 system. Each hexadecimal digit represents four binary places. The chart below shows the relationship between binary, hexadecimal, and decimal for 0x0-0xF.
|
Decimal |
Binary |
Hexadecimal |
|
0 |
0000 |
0x0 |
|
1 |
0001 |
0x1 |
|
2 |
0010 |
0x2 |
|
3 |
0011 |
0x3 |
|
4 |
0100 |
0x4 |
|
5 |
0101 |
0x5 |
|
6 |
0110 |
0x6 |
|
7 |
0111 |
0x7 |
|
8 |
1000 |
0x8 |
|
9 |
1001 |
0x9 |
|
10 |
1010 |
0xA |
|
11 |
1011 |
0xB |
|
12 |
1100 |
0xC |
|
13 |
1101 |
0xD |
|
14 |
1110 |
0xE |
|
15 |
1111 |
0xF |
Table 5 Decimal, binary, and hexadecimal conversions
Let us convert 0x3B to decimal via binary. The first step is to find out what the individual hexadecimal number represents in binary. Replace the hexadecimal number with the binary number. Therefore, 0x3B becomes 001110112. As you may recall from the previous section on binary, converting numbers from binary to decimal is much easier than with other systems, since multiplying by binary digits of 0 and 1 are trivial.
0x3B=
001110112=
32
+ 16 + 8 + 2 + 1 =
59
A byte of data (eight bits) can be written as just two hex digits. For example, the character "N" in extended ASCII code has the binary representation 01001110. If we write this as two groups of four bits each, we get 0100.1110. Using table 5 above, we find that 0100 is 0x4 and 1110 is 0xE. Therefore, the corresponding hexadecimal code for 0100.1110 is 0x4E.
When setting up or maintaining a computer system, you will sometimes encounter hexadecimal numbers as representations of memory addresses, network addresses, or other hardware-related qualities. You may encounter them in operating system-related contexts as well, such as when a machine "crashes" and displays a failure report.
Learning Exercise
You can experiment with conversions between binary, decimal, and hexadecimal using the Microsoft Calculator accessory.
|