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

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.

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.

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.

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.