《数字电子技术英文版.ppt》由会员分享,可在线阅读,更多相关《数字电子技术英文版.ppt(67页珍藏版)》请在三一办公上搜索。
1、CHAPTER 2NUMBER 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,th
2、e 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
3、base,which is 10.We can rewrite this:,To find the decimal value of a number,multiply each digit by its weight and sum the products.,Nothing Special about 10!,Decimal system(and the idea of“0”)was invented in India around 100-500AD.Why did they use 10?Anything special about it?Not really.Probably the
4、 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
5、 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 two digits(bits)are 1 and 0.The position of a 1 or 0 in a binary number indicates its weight,or v
6、alue within the number,just as the position of a decimal digit determines the value of that digit.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.,Counting Tennis Bal
7、ls Going into a box from a Conveyor Belt,The counter counts the pulses from a sensor that detects the passing of a ball and produces a sequence of logic levels(digital waveforms)on each of its four parallel outputs.Each set of logic levels represent a 4-bit binary number.The decoder decodes each set
8、 of four bits and converts it to the corresponding decimal number in the 7-segment display.,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 20=1.The weights increase from right to lef
9、t 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 l
10、eft to right by a negative power of two for each bit.The weight structure of a binary number is,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-3 DECIMAL-TO-BINARY CONVE
11、RSION,Repeated Division-by-2 Method,A systematic method of converting whole numbers from decimal to binary is the repeated devision-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 proces
12、s.,2-4 BINARY ARITHMETIC,Binary Addition,The four basic rules for adding binary digits(bits)are as follows:,0+0=0 Sum of 0 with a carry of 00+1=1 Sum of 1 with a carry of 01+0=1 Sum of 1 with a carry of 01+1=0 Sum of 0 with a carry of 1,Example Add 1111 and 1100.,Binary Subtraction,The four basic ru
13、les for subtraction binary digits(bits)are as follows:,0-0=0 Difference of 0 with a borrow of 00-1=1 Difference of 1 with a borrow of 11-0=1 Difference of 1 with a borrow of 01-1=0 Difference of 0 with a borrow of 0,Example Subtract 100 from 111.,Binary Multiplication,The four basic rules for multip
14、lication binary digits(bits)are as follows:,Example Multiply 1101 by 1010.,Binary Division,Division in binary follows the same procedure as division in decimal.,Example Divide 1100 by 100.,2-5 1S AND 2S COMPLEMENTS OF BINARY NUMBERS二进制的反码和补码,Finding the 1s Complement of a Binary Number,The 1s comple
15、ment of a binary number is found by changing all 1s to 0s and all 0s to 1s.,Example Find the 1s complement of binary number 10110010.,Finding the 2s Complement of a Binary Number,The 2s complement of a binary number is found by adding 1 to the 1s complement.,Example Find the 2s complement of binary
16、number 10110010.,2-6 SIGNED NUMBERS带符号数,The Sign Bit,The left-most bit in a signed binary number is the sign bit,which tells you whether the number is positive or negative.A 0 is for positive,and a 1 is for negative.,Sign-Magnitude System,When a signed binary number is represented in sign-magnitude,
17、the left-most bit is the sign bit and the remaining bits are the magnitude bits.The magnitude bits are in true(uncomplemented)binary for both positive and negative numbers.,The decimal values are determined by summing the weights in all the magnitude bit positions where there are 1s.The sign is dete
18、rmined by examination of the sign bit.,Sign-Magnitude System,Example 2-15 Determine the decimal value of this signed binary number expressed in sign-magnitude:10010101.,1s Complement System,Positive numbers in the 1s complement system are represented the same way as the positive sign-magnitude numbe
19、rs.Negative numbers,however,are the 1s complements of the corresponding positive numbers.,The decimal values of positive numbers are determined by summing the weights in all bit positions where there are 1s.The decimal values of negative numbers are determined by summing the weights in all bit posit
20、ions where there are 1s,and adding 1 to the result.The weight of the sign bit is given a negative value.,1s Complement System,Why?,1s Complement System,Example 2-16 Determine the decimal value of the signed binary numbers expressed in 1s complement:(a)00010111(b)11101000.,2s Complement System,Positi
21、ve numbers in the 2s complement system are represented the same way as in sign-magnitude and 1s complement systems.Negative numbers are the 2s complements of the corresponding positive numbers.,The decimal values are determined by summing the weights in all bit positions where there are 1s.The weigh
22、t of the sign bit is given a negative value.,2s Complement System,Example 2-17 Determine the decimal value of the signed binary numbers expressed in 2s complement:(a)01010110(b)10101010.,2s Complement Advantage,To convert to decimalThe 2s complement system simply requires a summation of weights rega
23、rdless of whether the number is positive or negative.The sign-magnitude system requires two steps sum the weights of the magnitude bits and examine the sign bit to determine if the number is positive or negative.The 1s complement system requires adding 1 to the summation of weights for negative numb
24、ers but not for positive numbers.Also,the 1s complement system is not used because two representations of zero(00000000 or 11111111)are possible.,The Development,The 2s complement of an n-bit number x is defined by,For example,if n=8,then,The Development,and,Range of Signed Integer Numbers,The numbe
25、r of different combinations of n bits is,For 2s complement signed numbers,the range of value for n-bit numbers is,By the Way,The 8-bit grouping has been given the special name byte.,Floating-Point Numbers(浮点数),Not required!,2-7 ARITHMETIC OPERATIONS WITH SIGNED NUMBERS带符号数的算术运算,Addition(加法),The two
26、numbers in an addition are the addend(加数)and the augend(被加数).The results are the sum(和)and the carry(进位).,The addition process is stated as follows:add the two numbers and discard any final carry bit.,Example(a)00000111+00000100=?(b)00001111+11111010=?(c)00010000+11101000=?(d)11111011+11110111=?,Ove
27、rflow Condition(溢出条件),When two numbers are added and the number of bits required to represent the sum exceeds the number of bits in the two numbers,an overflow results as indicated by an incorrect sign bit.An overflow can occur only when both numbers are positive or both numbers are negative.,Exampl
28、e(a)01111101+00111010=?(b)10001000+11101101=?,Subtraction(减法),The two numbers in a subtraction are the subtrahend(减数)and the minuend(被减数).The results are the difference(差)and the borrow(借位).,The subtraction process is stated as follows:take the 2s complement of the subtrahend and add.Disiscard any f
29、inal carry bit.,Example(a)0001000-00000011=?(b)11100111-00010011=?,Multiplication(乘法),The two numbers in a multiplication are the multiplier(乘数)and the multiplicand(被乘数).The result is the product(积).,The multiplication operation in most computers is accomplished using partial product method(部分积方法).T
30、he basic steps in the process are as follows:Determine if the signs of the two numbers are the same.This determines what the sign of the product will be.Change any negative number to true(uncomplemented)form.Starting with the LSB of the multiplier,generate the partial products.Shift each successive
31、partial product one bit to the left.Add each partial product to the sum of the previous partial products to get the final product.If the sign of the product is negative,take the 2s complement of the product.Attach the sign bit to the product.,Multiplication,Example 2-22 Multiply the signed binary nu
32、mber 01010011 and 11000101.,Division(除法),The two numbers in a division are the divisor(除数)and the dividend(被除数).The results are the quotient(商)and the remainder(余数).,The basic steps in a division the process are as follows:Determine if the signs of the two numbers are the same.This determines what t
33、he sign of the quotient will be.Initialize the quotient to zero and initialize the partial remainder to the dividend.Subtract the divisor from the partial remainder using 2s complement addition to get the next partial remainder.If the result is positive,add 1 to the quotient and repeat for the next
34、partial remainder;otherwise,the division is complete.,Division,Example 2-23 Divide 01100100 by 00011001.,2-8 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 mic
35、roprocessors 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
36、.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 num
37、ber 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:,Hexadecimal-to-Binary Conversion,Very straightforward!Simply replace each hexadecimal symbol with the equivalent
38、4-bit group.Example 2-25 Determine the binary numbers for the following hexadecimal numbers:(a)10A4h(b)CF8Eh(c)9742h,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 hexadec
39、imal numbers to decimal:(a)E5h(b)B2F8h,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-10 BINARY CODED DECIMAL(BCD),Introductory Parag
40、raph,Binary coded decimal(BCD)is a way to express each of the decimal digits with a binary code.Since there are only ten code groups in the BCD system,it is very easy to convert between decimal and BCD.Because we like to read and write in decimal,the BCD code provides an excellent interface to binar
41、y systems.Examples of such interfaces are keypad inputs and digital readouts.,The 8421 Code,The 8421 code is a type of BCD code.BCD means that each decimal digit,0 through 9,is represented by a binary code of four bits.,The designation 8421 indicates the binary weights of the four bits.1010,1011,110
42、0,1101,1110,and 1111 are invalid codes.The 8421 code is the predominant BCD code,and when we refer to BCD,we always mean the 8421 code unless otherwise stated.,The 8421 Code,To express any decimal number in BCD,simply replace each decimal digit with the appropriate 4-bit code.Example 2-33 Convert ea
43、ch of the following decimal numbers to BCD.(a)35(b)98(c)170(d)2469,To determine a decimal number from a BCD number,start at the right-most bit and break the code into groups of four bits,then write the decimal digit represented by each 4-bit group.Example 2-34 Convert each of the following BCD codes
44、 to decimal:,BCD Addition,BCD is a numerical code and can be used in arithmetic operations.Here is how to add two BCD numbers:Add the two BCD numbers,using the rules for binary addition.If a 4-bit sum is equal to or less than 9,it is a valid BCD number.If a 4-bit sum is greater than 9,or if a carry
45、out of the 4-bit group is generated,it is an invalid result.Add 6(0110)to the 4-bit sum in order to skip the six invalid codes and returned the code to 8421.If a carry results when 6 is added,simply add the carry to the next 4-bit group.Example Add the BCD numbers:00010110+00010101.,2-11 DIGITAL COD
46、ES AND PARITY数字编码和奇偶校验,Introductory Paragraph,There are many specialized codes used in digital systems.You have just learned about the BCD code;now lets look at a few others.Some codes are strictly numeric,like BCD,and others are alphanumeric;that is,they are used to represent numbers,letters,symbol
47、s,and instructions.The code introduced in this section are the Gray code and the ASCII code.Also,the detection of errors in codes using a parity bit is covered.,The Gray Code(格雷码),The Gray code is unweighted and is not an arithmetic code;that is,there are no specific weights assigned to the bit posi
48、tions.The important feature of the Gray code is that it exhibits only a single bit change from one code number to the next.相邻码,Binary-to-Gray code Conversion,The MSB in the Gray code is the same as the corresponding MSB in the binary number.Going from left to right,add each adjacent pair of binary c
49、ode bits to get the next Gray code bit.Discard carries.,Gray-to-Binary Conversion,The MSB in the binary code is the same as the corresponding MSB in the Gray code.Going from left to right,add each binary code bit generated to the Gray code bit in the next adjacent position.Discard carries.,Applicati
50、on Example,A simplified diagram of a 3-bit shaft position encoder mechanism(三位轴角位置编译器)is shown below.,Application Example,Consider what happens if one brush(for example,the MSB brush)is slightly ahead of the others during the transition from one sector to the next.,Alphanumeric Codes(字母数字编码),In the