CHAPTER 2 NUMBER SYSTEMS, OPERATIONS, AND CODES 数制系统、运算和编码 主讲教师:谷雷

Preview:

Citation preview

CHAPTER 2

NUMBER SYSTEMS,OPERATIONS,

AND CODES

数制系统、运算和编码

主讲教师:谷雷

2-1 DECIMAL NUMBERS

十进制数

Introductory Paragraph

You are familiar with the decimal number system because you use decimal numbers every day. Although decimal numbers are commonplace, their weighted structure is often not understood. In this section, the structure of decimal numbers is reviewed. Their review will help you more easily understand the structure of the binary number system, which is important in computers and digital electronics.

Decimal Review

Numbers consist of a bunch of digits, each with a weight.

• These weights are all powers of the base, which is 10. We can rewrite this:1 6 2 . 3 7 5 Digits102 101 100 10-1 10-2 10-3 Weights

• To find the decimal value of a number, multiply each digit by its weight and sum the products.

162.375 105 10 7 10 3 10 2 10 6 10 1 -3-2-1012

1 6 2 . 3 7 5 Digits 100 10 1 1/ 10 1/ 100 1/ 1000 Weights

Nothing Special about 10!

Decimal system (and the idea of “0”) was invented in India around 100-500A.D.

Why did they use 10? Anything special about it? Not really. Probably the fact that we have 10 fingers

influenced this. Will a base other than 10 work?

Sure. • What about base 2?

2-2 BINARY NUMBERS二进制数

Introductory Paragraph

The binary number system is simply another way to represent quantities. The binary system is less complicated than the decimal system because it has only two digits. It may seem more difficult at first because it is unfamiliar to you. The decimal system with its ten digits is a base-ten system; The binary system with its two digits is a base-two system. The weights in a binary number are based on powers of two.

Counting in Binary

A binary count of 0 through 15 is shown below. As you will see, 4 bits are required to count from 0 to 15.

The Weighting Structure of Binary Numbers

A binary number is a weighted number (加权数) . The right-most bit is the LSB (最低有效位) in a binary whole number and has a weight of 1(20). The weights increase from right to left by a power of two for each bit. The left-most bit is the MSB (最高有效位) .

Fractional numbers (小数) can also be represented in binary by placing bits to the right of the binary point. The left-most bit is the MSB in a binary fractional number and has a weight of 2-1=0.5. The fractional weights decreases from left to right by a negative power of two for each bit.

The weight structure of a binary number is

3210123 222.2222

2-2-1 Binary-to Decimal Conversion

The decimal value of any binary number can be found by adding the weights of all bits that are 1 and discarding the weights of all bits that are 0.

2-2-2 DECIMAL-TO-BINARY CONVERSION Repeated Division-by-2 Method

A systematic method of converting whole numbers from decimal to binary is the repeated division-by-2 process.

Repeated Multiplication-by-2 Method A systematic method of converting

fractional numbers from decimal to binary is the repeated multiplication-by-2 process.

2-7 HEXADECIMAL NUMBERS (十六进制数)

Why Hexadecimal?

As you are probably aware, long binary numbers are difficult to read and write because it is easy to drop or transpose a bit. Since computers and microprocessors understand only 1s and 0s, it is necessary to use these digits when you program in machine language.

The hexadecimal number system has 16 digits and is used primarily as a compact way of displaying or writing binary numbers because it is very easy to convert between binary and hexadecimal.

10 numeric digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and 6 alphabetic characters (A, B, C, D, E, F) make up the hexadecimal number system.

Relationship between hexadecimal and binary

Each hexadecimal digit represents a 4-bit binary number.

Binary-to-Hexadecimal Conversion

Very straightforward! Simply break the binary number into 4-bit groups, starting at the right-most bit and replace each 4-bit group with the equivalent hexadecimal symbol.

[Example 2-24] Convert the following binary numbers to hexadecimal:(a) 1100101001010111 (b) 111111000101101001

Hexadecimal-to-Binary Conversion

Very straightforward! Simply replace each hexadecimal symbol with the equivalent 4-bit group.

[Example 2-25] Determine the binary numbers for the following hexadecimal numbers:(a) (10A4)16 (b) (CF8E)16

Hexadecimal-to-Decimal Conversion

Multiply the decimal value of each hexadecimal digit by its weight and then take the sum of these products.

[Example 2-27] Convert the following hexadecimal numbers to decimal:(a) (E5)16

(a) (E5)16=14×161+5 ×160=(304)10

Decimal-to-Hexadecimal Conversion

Repeated division of a decimal number by 16 will produce the equivalent hexadecimal number.

[Example 2-28] Convert the decimal number 650 to hexadecimal by repeated division by 16.

2-8 OCTAL NUMBERS (八进制数)

Like the hexadecimal system, the octal system provides a convenient way to express binary numbers and codes. However, it is used less frequently than hexadecimal in conjunction with computers and microprocessors to express binary quantities.

The octal number system is composed of eight digits, which are

0, 1, 2, 3, 4, 5, 6, 7

Octal-to-Decimal Conversion

The evaluation of an octal number in terms of its decimal equivalent is accomplished by multiplying each digit by its weight and summing the products, as illustrated here for(2374)8.

Weight: 83 82 81 80

Octal number: 2 3 7 4

(2374)8 = (2× 83) + (3× 82) + (7× 81) + (4× 80)

= (2×512) + (3×64) + (7×8) + (4×1) = 1024 + 192 + 56 + 4 = (1276)10

Decimal-to-Octal Conversion

Repeated division of a decimal number by 8 will produce the equivalent Octal number.

[Example] Convert the decimal number 359 to Octal by repeated division by 8.

(547)8

Because each octal digit can be represented by a 3-bit binary number, it is very easy to convert from octal to binary. Each octal digit is represented by three bits as shown in tab 2-4 .

TABLE 2-4

Octal/binary conversion.

[Example 2-28] Conversion each of the following octal

numbers to binary :(a) 138 (b) 258 (c) 1408

Octal-to-Binary Conversion

Octal Digit 0 1 2 3 4 5 6 7

Binary 000 001 010 011 100 101 110 111

Binary-to-Octal Conversion

Break the binary number into 3-bit groups, starting at the right-most bit and replace each 3-bit group with the equivalent Octal numbers.

[Example 2-29] Convert the following binary numbers to Octal:(a) 110101 (b) 101111001

Summary of Conversion of Number Systems

1.R – to – Decimal Conversion Method : Multiply the decimal value of each R digit b

y its weight and then take the sum of these products.

a.(1101.101)2

b. (105.51)8

c. (2AE.B5)16

=1×23+1×22+0×21+1×20+1×2-1+0×2-2+1×2-3

=(13.625)10

= 1×82+0×81+5×80+5×8-1+1×8-2

=(69.640625)10

= 2×162+10×161+14×160+11×16-1+5×16-2

=(686.70703)10

2.Decimal – to – R ConversionMethod : Decimal-Binary-R

1.repeated division-by-2 2.repeated multiplication-by-2

(25.7)10=(11001.1011)2

=(31.54)8

=(19.B)16

3.Binary Octal Hexadecimal

(1110.0111)2=(16.34)8=(E.7)16

(6.44)8=(0110.1001)2=(6.9)16

(3D.BE)16=(00111101.10111110)2=(75.574)8

Recommended