Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Lectures_SSD2_Yermakova / Lectures_SSD2 Yermakova.doc
Скачиваний:
226
Добавлен:
25.02.2016
Размер:
3.16 Mб
Скачать

Hexadecimal

You should notice that it takes more digits to express a value in binary notation than in decimal notation. For example, the number 99 in decimal is 1100011 in binary. Computer professionals have adopted hexadecimal notation as shorthand for binary so that they can express binary values more concisely.

Hexadecimal (base16), or "hex," is most likely the largest numbering system that you will work with. In the modern decimal system, the Arabic number set 0-9 has to be supplemented by additional values to represent the decimal equivalents of 10, 11, 12, 13, 14, and 15. Instead of inventing new symbols to represent these numbers, the letters A-F are used. Hexadecimal is represented by the set of numbers 0-F. While both lower case and upper case letters can be used in hexadecimal for A-F. In this course, we will use upper case A-F. Hexadecimal, however, is not usually represented by appending a 16 as a subscript to the number. There are two differing formats for representing hexadecimal numbers: prepending 0x or appending h. We will use 0x to denote hexadecimal numbers.

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.