数字逻辑设计与应用:Lec04 Chap. 2 Number systems and Codes

上传人:大米 文档编号:571836588 上传时间:2024-08-12 格式:PPT 页数:46 大小:1.12MB
返回 下载 相关 举报
数字逻辑设计与应用:Lec04 Chap. 2 Number systems and Codes_第1页
第1页 / 共46页
数字逻辑设计与应用:Lec04 Chap. 2 Number systems and Codes_第2页
第2页 / 共46页
数字逻辑设计与应用:Lec04 Chap. 2 Number systems and Codes_第3页
第3页 / 共46页
数字逻辑设计与应用:Lec04 Chap. 2 Number systems and Codes_第4页
第4页 / 共46页
数字逻辑设计与应用:Lec04 Chap. 2 Number systems and Codes_第5页
第5页 / 共46页
点击查看更多>>
资源描述

《数字逻辑设计与应用:Lec04 Chap. 2 Number systems and Codes》由会员分享,可在线阅读,更多相关《数字逻辑设计与应用:Lec04 Chap. 2 Number systems and Codes(46页珍藏版)》请在金锄头文库上搜索。

1、1 1Digital Logic Design and ApplicationLecture #4Chap. 2 Number systems and CodesUESTC, Spring 2013Digital Logic Design and ApplicationIntroduction 所有信息都可以用有限位的二所有信息都可以用有限位的二进制数字表示,制数字表示,因此数字系因此数字系统可以可以处理任何信息。理任何信息。如何用二如何用二进制数字量来表示、运算信息制数字量来表示、运算信息模模拟量有正、量有正、负之分之分模模拟量有整、零之量有整、零之别除了二除了二进制制还有其他表示方法有其他

2、表示方法吗不能或不便抽象不能或不便抽象为两两值子集的信息如何子集的信息如何处理?理?2Digital Logic Design and Application学习要求学习要求掌掌握握:十十进制制、二二进制制、八八进制制和和十十六六进制制数数的的表表示示方方法法以以及及它它们之之间的的相相互互转换、二二进制制数数的的运运算算;符符号号数数的的表表达达:符符号号-数数值码(Signed-Magnitude System、原原码),二二进制制补码(twos complement,补码)、二二进制制反反码(ones complement, 反反码)表表示示以以及及它它们之之间的的相相互互转换;符号数的

3、运算;溢出的概念符号数的运算;溢出的概念。掌掌握握:其其他他信信息息的的编码表表达达:BCD码(Binary Codes for Decimal numbers)、n中中取取1码(独独热码)、格格雷雷码(Gray code)的特点及其与二)的特点及其与二进制数之制数之间的的转换关系;关系;了解:模了解:模拟信息的数字表达:信息的数字表达:A/D转换的基本概念;的基本概念;了了解解:字字符符的的代代码表表示示,二二进制制代代码在在状状态、条条件件等等的的表表示方面的示方面的应用;用;3Digital Logic Design and Application2.1 Positional Numbe

4、r system用用进位位的的方方法法进行行计数数的的数数制制称称为进位位计数数制制(或或按位按位计数制数制 Positional Number system)。4DigitRadixNumberWeighted sum of the digits.WeightDigital Logic Design and Application2.1 Positional Number system5数制的数制的三要素三要素为:数数码(digit):0r-1,进位位规律律:逢逢r进一一,借一当借一当r。基基数数(base/radix):数数码的的进制制数数r,也也称称为基数(底数)。基数(底数)。位位权(

5、weight):ri,数数码在在一一个个数数中中的的位位置置不不同同,其其大大小小就就不不同同。i是是数数码所所在在的的位位置置,称称为数位。数位。Digital Logic Design and Application2.1 Positional Number systemDecimalDecimal(十进制)(十进制)Digit:0 9,逢,逢10进1,借,借1当当10Weight:(10) 10 iRadix: 10 Digital Logic Design and Application2.1 Positional Number systemBinaryBinary ( (二进制二进制

6、 ) )Digit :0 1,逢,逢2进1,借一当,借一当2Weight: (2) 10 iRadix: 2Digital Logic Design and Application二二进制的制的优点:运算点:运算简单,电路路简单,工,工作可靠。数字作可靠。数字电路中多使用二路中多使用二进制制.二二进制的不足:一个制的不足:一个较大的十大的十进制用二制用二进制表示需要制表示需要较多的位,多的位,为了克服二了克服二进制制书写太写太长的缺点,常用八的缺点,常用八进制和十六制和十六进制。制。2.1 Positional Number systemDigital Logic Design and App

7、licationOctal(八(八进制)制)Digit:0 7,逢,逢8进1,借,借1当当8Weight: (8) 10 iRadix:8 Hexadecimal(十六进制)(十六进制)Digit:0 9 AF(1015),逢,逢16进进1,借,借1当当16Weight:(16) 10 iRadix:162.2 Octal & Hexadecimal NumbersDigital Logic Design and Application计数制计数制数码数码位权位权 基数基数举例举例十进制十进制 0910i10(123)10 (456.321)D二进制二进制 0, 12i2(1010)2 (10

8、01.101)B八进制八进制 078i8(567)8 (745.217)O十六十六进制进制09、AF 16i16(2A2B)16 (1B3.EC)H下标:下标:D:Decimal; B:Binary; O: Octal; H: Hexadecimal2.2 Octal & Hexadecimal NumbersDigital Logic Design and Application2.2 Octal & Hexadecimal Numbers任何一种数制的任何一种数制的权以本身数制来表示都是以本身数制来表示都是10i;任任何何一一种种数数制制,相相同同数数码所所表表示示的的数数值大大小小都都是

9、是相相等的;等的;任任何何一一种种数数制制,乘乘以以基基数数r等等于于将将数数字字向向左左移移动一一位,除以基数位,除以基数r等于将数字向右移等于将数字向右移动一位;一位;几个几个术语最高有效位(最高有效位( Most Significant Bit ,MSB)最低有效位(最低有效位( Least Significant Bit ,LSB)任何一种数制,其位任何一种数制,其位权均是左高右低。均是左高右低。11Digital Logic Design and Application122.3 General Positional-Number-System Conversion2.3.1 Rad

10、ix-r-to-Decimal (R 进制制-十十进制制)Example 1:( 101.01 )2 = ( )10 ( 7F.8 )16 = ( )105.25127.5A shortcut? ( F1AC )16 = ( ( ( F16 ) +1 ) 16 + A ) 16 + CMethod: use the formula nested expansion formula nested expansion formula 嵌套形式嵌套形式Digital Logic Design and Application( 0.1101 )2 = ( )2/ = ( )10=2.3 General

11、 Positional-Number-System Conversion13Fraction part conversion(小数的转换小数的转换)任意数制的小数部分均小于任意数制的小数部分均小于1;数制转换不影响整数和小数部分;数制转换不影响整数和小数部分;可以分开转换,按权展开;可以分开转换,按权展开;也可以按照整数处理,最后移动小数点。也可以按照整数处理,最后移动小数点。 2.3.1 Radix-r-to-Decimal (R 进制进制-十进制十进制)Example :( 0.1101 )2 = ( )10= ( )10( 10.11 )2=( )10Digital Logic Desi

12、gn and Application142.3.2 Decimal-to-Radix-r Conversions (十进制十进制-R进制进制)Convert the integer and fractional parts separately and add the results afterwards.(1)Integer part: Successively divide number by r, taking remainder as result.Example: Convert 5710 to binary57 / 2 = 28 remainder 1 (LSB) /2 = 14

13、remainder 0 /2 = 7 remainder 0 /2 = 3 remainder 1 /2 = 1 remainder 1 /2 = 0 remainder 1 (MSB)Ans: 11100122.3 General Positional-Number-System ConversionDigital Logic Design and Application152.3.2 Decimal-to-Radix-r Conversions (十进制十进制-R进制进制)(2)Fractional PartSuccessively multiply number by r, taking

14、 integer part as result and chopping off integer part before next iteration.May be unending!Example: convert .310 to binary.3 * 2 = .6 integer part = 0.6 * 2 = 1.2 integer part = 1.2 * 2 = .4 integer part = 0.4 * 2 = .8 integer part = 0.8 * 2 = 1.6 integer part = 1.6 * 2 = 1.2 integer part = 1, etc.

15、Ans: .01001122.3 General Positional-Number-System ConversionDigital Logic Design and Application162.3.2 Decimal-to-Radix-rMethod: Radix Multiplication or Division 1001 11001001 11000.01011 0.01011 2.3 General Positional-Number-System ConversionInteger Parts 整数部分:除整数部分:除r r取余,逆序排列取余,逆序排列 Example 2:(

16、156 )10 = ( )2Decimal Fraction 小数部分:乘小数部分:乘r r取整,顺序排列取整,顺序排列 Example 3:( 0.37 )10 = ( )2 2 2-5-5Digital Logic Design and Application172.3.2 Decimal-to-Radix-rMethod: Radix Multiplication or Division 2.3 General Positional-Number-System ConversionInteger Parts 整数部分:除整数部分:除r r取余,逆序排列取余,逆序排列Decimal Fra

17、ction 小数部分:乘小数部分:乘r r取整,顺序排列取整,顺序排列Digital Logic Design and Application2.3 General Positional-Number-System Conversion2.3.2 Decimal-to-Radix-r18Example Example 4 4:RequireRequire 10 10-2-2 ,complete the complete the following conversionfollowing conversion ( 617.28 ) ( 617.28 )10 10 = ( )= ( )2 210

18、0110 1001 . 0100 01110 0110 1001 . 0100 0112 2- -n n = 10 10-2 -2 n = 7n = 7Digital Logic Design and Application2.3 General Positional-Number-System Conversion八八进制制/十六十六进制的制的权是是2的的幂,因此与二,因此与二进制之制之间的的转换十分容易;十分容易;一位八一位八进制数制数码可用可用3位二位二进制数制数码表示;表示;一位十六一位十六进制数制数码可用可用4位二位二进制数制数码表示;表示;不足位不足位补零。零。192.3.2 Bi

19、nary to Octal/Hex( 100110 )( 100110 )2 2 = ( = ( ) )8 84646( 100110 )( 100110 )2 2 = ( = ( ) )2 2= ( )= ( )16160010 01100010 011026Digital Logic Design and Application20 ( 0010 1100 0110 ) ( 0010 1100 0110 )2 2 = ( = ( ) )10102.3 General Positional-Number-System Conversion2.3.2 Binary to Octal/HexUs

20、e Hexadecimal as the middle state between Binary and Decimal.(0010 1100 0110 )(0010 1100 0110 )2 2 = ( )= ( )1616= ( = ( ) )10102 C 6 2 C 6 710710( 1000 1)( 1000 1)10 10 = ( )= ( )2 2(10001 )(10001 )10 10 = ( )= ( )1616= ( = ( ) )2 2271127110010 0111 0001 0010 0111 0001 00010001Digital Logic Design

21、and Application2.3 General Positional-Number-System Conversion小数小数转换的精度的精度转换时不不应低于原精度低于原精度受受实际数字系数字系统的限制的限制可可以以采采取取零零舍舍一一入入的的近近似似方方法法:即即小小数数点点后后第第n+1位位是是1则将将其其进位位到到第第n位位,如如为零零,则舍舍去去,结果果为小数点后小数点后n位位.212 2- -n n = 10 10-m -m Digital Logic Design and Application222.4 Addition and Subtraction of Nondeci

22、mal NumbersBinary Addition: SCoutXYCinAdderDBoutXYBinSubtracterDigital Logic Design and Application23Binary addition truth table Tab. 2-3InputOutputXYCinSCout0000001010100101100100110011011010111111Parity CheckDigital Logic Design and Application24Binary subtraction truth table Tab. 2-3inputoutputXY

23、BinBoutD0000001011100011100000111011101010011111Digital Logic Design and Application2.4 Addition and Subtraction of Nondecimal Numbersexample25 1011 1110+ 1000 1101 1010 1010 0101 0101Use truth tableUse the basic function unit 1 0100 1011 0101 0101Build a 4-bit unsigned number full adder.Digital Log

24、ic Design and Application262.5 Representation of Negative Numbers无符号数加法的溢出无符号数加法的溢出 ( overflow )及处及处理理 1011 1110+ 1000 1101 1 0100 1011 190 + 141331 为什么使用符号数,什么时候使用符号数为什么使用符号数,什么时候使用符号数符号数的表示符号数的表示Digital Logic Design and Application272.5 Representation of Negative NumbersSigned-Magnitude Representa

25、tion 符号符号- -数值表示数值表示法法/ /原码原码MSB as the sign bit ( 0 = plus, 1 = minus ) 000010012 = +910 100010012 = 910 011111112 = +12710 111111112 = 12710 000000002 = +010 100000002 = 010There are two possible representations of Zero.An n-bit signed-magnitude integer range is ( 2n-11) + ( 2n-11) An equal number

26、 of positive and negative integers.Adder for signed-magnitude number is much difficult.Digital Logic Design and Application282.5 Representation of Negative Numbers原原码不能做加法不能做加法The need for Complement Number Systems 0011 1101+ 1011 11011111 1010A+(-A)0A+(-A)=0+3 011- 3 101有有了了补补码码,可可以以用用加加法法完完成成减减法法,

27、单单独独的的减减法法规规则则就就是不必须的。是不必须的。Digital Logic Design and Application2.5 Representation of Negative NumbersComplement Number SystemsRadix-Complement Representation(基基数数补码) The complement of an n-digit number is obtained by subtracting it from rn。 If a number D is complemented twice, the result is D.Takin

28、g the complement is more difficult than changing the sign, but two numbers can be added directly. How to make it easy?29Digital Logic Design and Application2.5 Representation of Negative Numbers30Example 5. Example 5. 若字长是一个字节,试求若字长是一个字节,试求119119的补码。的补码。解:解:119119的绝对值:的绝对值:1191190111011101110111 则其补

29、码可以通过下式算法得到:则其补码可以通过下式算法得到: 28: 1 0 0 0 0 0 0 0 0减去减去119绝对值绝对值: 0 1 1 1 0 1 1 1119的补码:的补码: 1 0 0 0 1 0 0 1-119: 1 0 0 0 1 0 0 1+119: 0 1 1 1 0 1 1 1 1 0 0 0 0 0 0 0 0舍去舍去MSB的进位的进位Digital Logic Design and Application312.5 Representation of Negative NumbersComplement Number SystemsDiminished Radix-Com

30、plement(基数减(基数减1补码补码/反码)反码) The Diminished Radix-Complement of an n-digit number is obtained by subtracting it from rn -1.Digital Logic Design and Application32OnesComplement Representation (二进制反码二进制反码)The sign bit doesnt change, other bits converse based on the signed-magnitude. 符号位不符号位不变,其余在原其余在原码

31、基基础上按位取反上按位取反Twos-Complement Representation (二进制补码二进制补码)Onescomplement + 1Only one representations of Zero An n-bit twos-complement range is 2n-1 +(2n-11)Expanding the sign bit ( 符号位符号位扩展展 ) 2.5 Representation of Negative NumbersDigital Logic Design and Application33Example 5. Example 5. 若字长是一个字节,试求

32、若字长是一个字节,试求119119的补码的补码。解:首先计算解:首先计算119119的绝对值:的绝对值:1191190111011101110111 则其补码可以通过下式算法得到:则其补码可以通过下式算法得到: 全全1码:码:1 1 1 1 1 1 1 1减去减去119绝对值绝对值: 0 1 1 1 0 1 1 1119的反码:的反码:1 0 0 0 1 0 0 0 加加1: 1 119的补码:的补码:1 0 0 0 1 0 0 1Digital Logic Design and Application34NOTEPositive number has the same: Sign-Magni

33、tude, Ones- Complement, and Twos- Complement 正数的原码、反码、补码相同正数的原码、反码、补码相同Digital Logic Design and Application35 D D 反反 反反 = = D D D D 补补 补补 = = D D1 1、8 8位二进制表示:位二进制表示: 原码原码 反码反码 补码补码1 10000001101 1101 1 1111111 0010 0010 1 1111111 0011 0011Example 6:Write the 8-bit signed-magnitude, twos-complement r

34、epresentations for each of these binary numbers. ( 1101 )2 ( 0 . 1101 )2 原码原码 反码反码 补码补码1 1. .1101 1101 1.1.0010 0010 1.1.00110011Digital Logic Design and Application2.5 Representation of Negative Numbers为为什么什么补码补码可以做加法可以做加法?为为什么二什么二进进制的制的补码补码是按位取反再加是按位取反再加1?为为什么正数的原什么正数的原/反反/补码补码相同相同?36Digital Logic

35、 Design and Application37Only one representations of Zero ( 零只有一种表示零只有一种表示 ) 00 0 0 0 0 0 0 0 逐位取反逐位取反 1 1 1 1 1 1 1 1 1约定定8位位 0 0 0 0 0 0 0 001 0 0 0 0 0 0 0 = ? 约定定8bit字字长,补码表示范表示范围128127 -8Digital Logic Design and Application382.5 Representation of Negative NumbersOnesComplement Representation (二

36、进制反码二进制反码)符号位不符号位不变,其余,其余在原在原码基基础上上按位取反按位取反 或者或者 在相在相应正数的基正数的基础上上按位取反按位取反Twos-Complement Representation (二进制补码二进制补码)Onescomplement + 1 Only one representations of Zero An n-bit twos-complement range is 2n-1 +(2n-11)Extra number, 2n1, doesnt have a positive counterpartThe weight of the MSB is 2n1 ins

37、tead of +2n1.Expanding the sign bit ( 符号位符号位扩展展 ) Digital Logic Design and Application十进制十进制二进制原码二进制原码二进制反码二进制反码二进制补码二进制补码-81000-7111110001001-6111010011010-5110110101011-4110010111100-3101111001101-2101011011110-110011110111101000或或00001111或或000000001000100010001200100010001030011001100114010001000

38、100501010101010160110011001107011101110111Table 2-6 Decimal and 4-bit numbersDigital Logic Design and Application原码原码/反码反码/补码的小结补码的小结为了表示了表示负数才需要符号数的原数才需要符号数的原码;为了保了保证原原码加减法的正加减法的正确才需要确才需要负数的数的补码表达形式表达形式;正数的原正数的原/反反/补码相同相同.从正数从正数A计算算-A的的补码有两种等效方法有两种等效方法:-A的的补码=2n-A=A的原的原码按位取反按位取反(带符号位符号位)+1。从从负数数-A计

39、算算-(-A)的的补码有两种等效方法有两种等效方法:-(-A)的的补码= 2n-(-A)补=(-A)的的补码按位取反按位取反+1。正数的正数的补码MSB为0 ,负数的数的补码MSB为1.N位二位二进制原制原码/反反码/补码均可以表示均可以表示2n个数。个数。二二进制原制原码和反和反码中零有两种表达形式中零有两种表达形式,补码中零只有一种表中零只有一种表达方式达方式,即即+0。N位二位二进制制补码可以表示可以表示-2n-1,原原码/反反码中没有。中没有。二二进制原制原/反反/补码均有均有顺序序递增增/减的减的规律。律。40反码反码Digital Logic Design and Applicat

40、ion410000000100100011010001011000100110101101111111101011110001110110+0+1+2+3+4+5 8 7 6 3 1 2 5 4+7+64-bit twos-complement numbersDigital Logic Design and Application422.6 Twos-Complement Addition and SubtractionAddition Rules: By ordinary binary addition, ignoring any carries beyond the MSB; No dif

41、ferent cases based on operands signs!按照无符号数的加法规则相加按照无符号数的加法规则相加,符号位参加运算。符号位参加运算。3 1 1 0 1+ 5 + 1 0 1 18 1 1 0 0 0+7 0 1 1 1+ 4 + 1 1 0 0 +3 1 0 0 1 1+2 0 0 1 0+ +5 + 0 1 0 1+7 0 1 1 17 3 10 5 6 11 1 0 1 1+ 1 0 1 01 0 1 0 1 5 0 1 1 1 0 0 1 1 1 0 1 0 6 Digital Logic Design and Application432.6 Twos-Co

42、mplement Addition and subtractionOverflow(溢出(溢出) Occurs if result is out of rangeAddends with different sign will not produce an overflow. 异号数相加不会产生溢出异号数相加不会产生溢出.if the addends signs are the same but the sums sign is different from the addends.同同号号数数相相加加,结结果果为为异异号号则溢出。则溢出。If the carries into and out

43、 of the sign position are different. 符号位的符号位的 cin cout Digital Logic Design and Application442.6 Twos-Complement Addition and SubtractionSubtraction Rules: Taking subtrahends 2s-complement, then add it to minuendNegating the subtrahend, adding the minuend with Cin=1+4 +30100 001110100+ 11001 0001cin

44、 10010+ 00100101+2 30010 1101cin Overflow in subtraction can be detected using the same rule as in addition.Digital Logic Design and Application45第第2章作业章作业(P7476)2.1 (e) (i)(j)2.2 (a) (e)2.3 (b) (e)2.5 (e) (j)2.6 (b) (f)2.7 2.8 (a)2.9 (b)2.10 (c)2.11 ( +18 , 49)2.12 (b) (c)2.19(思考)(思考)2.26 (思考)(思考)2.332.34补充习题补充习题Digital Logic Design and ApplicationBackups46

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号