Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSD 2, lection, unit 1.doc
Источник:
Скачиваний:
10
Добавлен:
03.11.2018
Размер:
1.3 Mб
Скачать

1.3.2 Number Systems

  • Decimal

  • Binary

  • Hexadecimal

  • Learning Exercise

The world of computing uses several number systems to represent data. While the decimal system, also known as base10, will be familiar to people, as it is the numbering system used in everyday life, binary (base2) and hexadecimal (base16) are common number systems used in computing today.

Мир вычисления использований несколько систем номера(числа), чтобы представить данные. В то время как десятичная система, также известный как base10, будет знакома людям, поскольку это - система нумерации, используемая в каждодневной жизни, двоичный (base2) и hexadecimal (base16) - общие(обычные) системы номера(числа), используемые в вычислении сегодня.

Decimal

We will start our discussion on number systems by examining the decimal system as an example of a number system. The decimal number system contains ten values- 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Each number in the decimal number system can be broken into digits by their "place" in the number. Using the number 43,872 as an example, 2 is in its 0th place, 7 is in its first place, 8 in its second, 3 in its third, and 4 in its fourth. Each place has a value that can be represented either exponentially or by its decimal values. The following table shows the exponential and decimal representation for each place in the number 43,872.

Мы запустим наше обсуждение по системам номера(числа), исследуя десятичную систему как пример системы номера(числа). Десятичная система номера(числа) содержит десять значений, 1, 2, 3, 4, 5, 6, 7, 8, и 9. Каждый номер(число) в десятичной системе номера(числа) может быть, ворвался в цифры их "местом" в номере(числе). При использовании номера 43,872(числа), поскольку пример, 2 находится в его 0-ом месте, 7 находится в его первом месте, 8 в его секунде, 3 в его трети, и 4 в ее четвертый. Каждое место имеет значение, которое может быть представлено или по экспоненте или его десятичными значениями. Следующая таблица показывает показательному и десятичному представлению для каждого места в номере 43,872(числе).

Place

4th

3rd

2nd

1st

0th

Digit

4

3

8

7

2

Exponential value of the place

104

103

102

101

100

Decimal value of the place

10,000

1,000

100

10

1

Table 1 Exponential and decimal values corresponding to a digit's place in a number

Note that the exponential values are raised to a power corresponding to the place of the digit. For example, the exponential value of the 4th place is 104.

To determine the value of the number, multiply the digit contained in a column by the value that column represents. The following is a sample calculation for the previous example.

Где p - место, b - основа, dp - цифра в самом высоком месте в номере(числе), и dp-1 - следующее самое высокое место в номере(числе), и так далее.

4 × 104 + 3 × 103 + 8 × 102 + 7 × 101 + 2 × 100 = 4 × 10,000 + 3 × 1000 + 8 × 100 + 7 × 10 + 2 × 1 = 40,000 + 3000 + 800 + 70 + 2 = 43,872

While performing these calculations on a decimal number seems trivial, it demonstrates a pattern, or formula can be used to convert a number in any numbering system to decimal.

dp(b)p + dp-1(b)p-1 + . . . + d0(b)0

Where p is the place, b is the base, 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.

Пока, мы только обсудили номера(числа) преобразования к десятичному числу. Также важно быть способно конвертировать(преобразовать) номера(числа) от десятичного числа до других систем нумерации. При продолжении с base4 системой, позвольте нам конвертировать(преобразовывать) 89 от десятичного числа до base4.

Сначала, найдите значение p, где 4p < = 89 < 4p+1. В этом случае(регистре) p = 3. P - значение самого высокого места.

Using the number example above, dp = 4, dp-1 = 3, b = 10, and p = 4.

4 × 104 + 3 × 103 + 8 × 102 + 7 × 101 + 2 × 100 = 43,872

The formula above can be used to compute the decimal value of any number in a given base. Below is the calculation for converting 214 to its decimal value:

Place

1st

0th

Digit

2

1

Exponential value of the place

41

40

Decimal value of the place

4

1

Table 2 Exponential and decimal values corresponding to a digit's place in a number

2(4)1 + 1(4)0 = 2× 4 + 1 × 1 = 8 + 1 = 9

So far, we have only discussed converting numbers to decimal. It is also important to be able to convert numbers from decimal to other numbering systems. Continuing with the base4 system, let us convert 89 from decimal to base4.

First, find the value p, where 4p < = 89 < 4p+1. In this case p = 3. p is the value of the highest place.

Now we can proceed by filling out the following chart:

Place

3

2

1

0

Exponential value of the place

43

42

41

40

Decimal value of the place

64

16

4

1

Calculation

89 ÷ 64

25 ÷ 16

9 ÷ 4

1 ÷ 1

Result

1

1

2

1

Remainder

25

9

1

0

Table 3 Converting numbers from base 10 to base 4

Therefore, 8910 = 11214.

We are now going to review binary and hexadecimal more closely.

Binary

Since all numbering-systems are treated the same, you already have all the tools necessary to convert to and from binary. Let's review converting from binary to decimal the number 101101102.

The highest place, p, is obtained by counting the number of places in the binary number, starting from zero. In this case, p = 7.

1 × 27 + 0 × 26 + 1 × 25 + 1 × 24 + 0 × 23 + 1 × 22 + 1 × 21 + 0 × 20 = 1 × 128 + 0 × 64 + 1 × 32 + 1 × 16 + 0 × 8 + 1 × 4 + 1 × 2 + 0 × 1 = 128 + 0 + 32 + 16 + 0 + 4 + 2 + 0 = 182

For example, in 1001102 the largest place is 2p, where p = 5. Because binary is the easiest numbering system to convert into decimal, it will help us later when we are convert hexadecimal numbers.

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.

Learning Exercise

You can experiment with conversions between binary, decimal, and hexadecimal using the Microsoft Calculator accessory.

  • Using the Windows operating system, click the Start button, select Programs, then select Accessories, and then select Calculator. To perform the functions required in this exercise you must click the calculator's View menu and select Scientific.

  • To use the calculator for data conversion, click its Dec radio button to put the calculator into decimal mode, type a number, and then click the Hex radio button to convert the number to hexadecimal. You can convert from hexadecimal to decimal as well; the A-F keys are enabled whenever you are in hexadecimal mode.

  • What is the hexadecimal representation of the number 255? What is the decimal equivalent of 0x4D2?

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]