数字逻辑设计第2章3_第1页
数字逻辑设计第2章3_第2页
数字逻辑设计第2章3_第3页
数字逻辑设计第2章3_第4页
数字逻辑设计第2章3_第5页
已阅读5页,还剩27页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1Chapter 2 Number Systems and Codes(数字系统和编码) numeric quantities(数值) nonnumeric data, events, and conditions(非数值) binary number codeSigned-magnitude code (S-M code):Signed numberTwos complement code : Change the sign means change every bit, and add 1 at LSBSigned numberConverting rules for signed num

2、bersFrom unsigned to signed: Its MSB is changed to sign bit. The number must be a positive ! Beware the overflow !Key point: A positive signed number with any code must be the same ! Its MSB is “0” ! From one code to another Step 1: Check the MSB (sign-bit) ; For positive number (MSB =0) : no change

3、s !Step 2: For negative number (MSB =1) : first change its sign by the former code way; then change its sign by the next code way ! Examples : 01101001MSA11001010stwoB?stwoA?MSBFrom one code to another ?stwoA?MSB7 二进制的原码、反码、补码 正数的原码、反码、补码表示相同 负数的原码表示:符号位为 1 负数的反码表示: 符号位不变,其余在原码基础上按位取反 在 |D| 的原码基础上按位

4、取反(包括符号位) 负数的补码表示:反码 + 1MSBMSB的权是的权是2n 1Signed number8Write the 8-bit signed-magnitude, twos-complement, and ones-complement representations of +11910 ,-1710.signed-magnitudeTwos complementOnes- complement+11910011101110111011101110111-1710100100011110111111101110正数的原码、反码、补码相同正数的原码、反码、补码相同Signed num

5、ber9Sign extension(符号扩展)(符号扩展)4-bit number+61001108-bit number00000110- 610101011111010 Given an n-bit twos complement number X, the m-bit twos-complement representation of X, where mn, can be obtained by appending m-n copies of Xs sign bit to the left of the n-bit representation of X. Why?Signed nu

6、mber10Write the signed-magnitude, twos-complement, and ones-complement representations: 1 1、( ( 1101 ) 1101 )2 2 2 2、( ( 0 . 1101 ) 0 . 1101 )2 2 D D 反反 反反 = = D D D D 补补 补补 = = D D5-bit 5-bit representations: S-MS-M onesones two twos s1 1 1101 1101 1 1 0010 0010 1 1 0011 00118-bit representations8-

7、bit representations: S-MS-M onesones two twos s1) 11) 1000000 1101 1101 1 1111111 0010 0010 1 1111111 0011 0011112.2.6 Two6 Twos-Complement Addition and s-Complement Addition and SubtractionSubtraction(二进制补码的加法和减法)二进制补码的加法和减法)4 4-bit-bit000000010010001101000101100010011010110111111110101111000111011

8、0+0+1+2+3+4+5 8 7 6 3 1 2 5-4+7+6122.2.6 Two6 Twos-Complement Addition and s-Complement Addition and SubtractionSubtraction(二进制补码的加法和减法)二进制补码的加法和减法)p.40 Table 2-613TwoTwos-Complement Addition s-Complement Addition - 5+7+2 1 0 1 1+)0 1 1 1 1 0 0 1 0ignored- 5+3- 2 1 0 1 1+)0 0 1 1 1 1 1 0Addition Rul

9、e: Twos-complement numbers can be added by ordinary binary addition, ignoring any carries beyond the MSB. The result will always be the correct sum as long as the range of the number system is not exceeded.14- 5- 5- 10 1 0 1 1+)1 0 1 1 1 0 1 1 0ignored+5+4+9 0 1 0 1+) 0 1 0 0 1 0 0 1Overflow(溢出): An

10、 operation produces a result that exceeds the range of the number system.6 ?-7 ?Overflow rule(判断溢出规则): An addition overflows if the addends signs are the same but the sums sign is different from the addends.TwoTwos-Complement Addition s-Complement Addition 15TwoTwos-Complement Subtractions-Complemen

11、t Subtraction +4-) +3 +1 0 1 0 0-) 0 0 1 1ignored 0 1 0 0+)1 1 0 1 1 0 0 0 1Subtraction Rule: Negate the subtrahend by taking its twos complement, and then add it to the minuend using the normal rules for addition. Perform a bit-by-bit complement of the subtrahend and add the complemented subtrahend

12、 to the minuend with an initial carry( cin) of 1 instead of 0.16 +2-) - 5 +7 0 0 1 0-) 1 0 1 1 1 0 0 1 0+)0 1 0 0 0 1 1 1Subtraction Rule: Negate the subtrahend by taking its twos complement, and then add it to the minuend using the normal rules for addition. Perform a bit-by-bit complement of the s

13、ubtrahend and add the complemented subtrahend to the minuend with an initial carry( cin) of 1 instead of 0.TwoTwos-Complement Subtractions-Complement Subtraction17 +4-) - 5 +9 0 1 0 0-) 1 0 1 1 1 0 1 0 0+)0 1 0 0 1 0 0 1-7 ?OverflowOverflow rule(判断溢出规则): Overflow in subtraction can be detected by ex

14、amining the signs of the minuend and the complemented subtrahend, using the same rule as in addition.TwoTwos-Complement Subtractions-Complement Subtraction18Unsigned Binary Numbers Addition and Unsigned Binary Numbers Addition and SubtractionSubtraction(无符号二进制数的加法和减法)(无符号二进制数的加法和减法) 4+) 5 9 0 1 0 0+

15、) 0 1 0 1 1 0 0 14-bit binary number: 00001111Signed number: -8 +7Unsigned numbers: 0 15 8+) 9 1 7 1 0 0 0+) 1 0 0 1 1 0 0 0 1overflowOverflow rule(判断溢出规则): Overflow in unsigned addition or subtraction can be detected by examining the carry or borrow in the significant bit position.19 加法:按普通二进制加法相加

16、减法:将减数求补,再相加 溢出(overflow) 对于二进制补码,加数的符号相同,和的符号与加数的符号不同。 对于无符号二进制数,若最高有效位上发生进位或借位,就表示结果超出范围。2.2.6 Two6 Twos-Complement Addition and s-Complement Addition and SubtractionSubtraction(二进制补码的加法和减法)二进制补码的加法和减法)20 numeric quantitiesnumeric quantities(数值)(数值) nonnumeric data, events, and conditionsnonnumeri

17、c data, events, and conditions(非数值)(非数值) binary number codeCodeCode(编码)(编码): a set of n : a set of n bit strings in which bit strings in which different bit strings represent different numbers or different bit strings represent different numbers or other things.other things.If there are n different

18、actions,conditions, or states, we If there are n different actions,conditions, or states, we can represent them with a b-bit binary code withcan represent them with a b-bit binary code withCeiling function(上限函数)(上限函数) nbnb2log2 BCD code :10 Decimal digits , 4-bit ASCII code:128 Keyboard signs , 7-bi

19、t GB2312 code:6763 Chinese character , 16-bitCodes in binary system222.10 2.10 Binary Codes for Decimal Binary Codes for Decimal NumbersNumbers(十进制数的二进制编码)(十进制数的二进制编码)BCD code(binary-coded decimal code) How to represent the ten decimal digits?At least need _ bits.?p.49 Table 2-98421 codeNatural code

20、 , just like 4-bit binary numbers;Each digit is weighted;It has 10 valid code words and 6 invalid code words. 2.10 2.10 Binary Codes for Decimal Binary Codes for Decimal NumbersNumbers(十进制数的二进制编码)(十进制数的二进制编码)Each digit is weighted;Self-complementing;Use MSB to express higher/lower part;It has 10 val

21、id codes and 6 invalid codes.2421 codes2.10 2.10 Binary Codes for Decimal Binary Codes for Decimal NumbersNumbers(十进制数的二进制编码)(十进制数的二进制编码)Excess-3 codeIts digit is not weighted; Self-complementing ;8421 code + “0011” .2.10 2.10 Binary Codes for Decimal Binary Codes for Decimal NumbersNumbers(十进制数的二进制

22、编码)(十进制数的二进制编码)262.10 2.10 Binary Codes for Decimal Binary Codes for Decimal NumbersNumbers(十进制数的二进制编码)(十进制数的二进制编码)47.9610=( )8421BCD =( )2421BCD =( )excess-3 01000111.1001011001001101.1111110001111010.110010010011100101018421BCD=( )20011100101018421BCD=( )10 395 110001011272.10 Binary Codes for Dec

23、imal Numbers(十进制数的二进制编码)BCD addition: Addition of BCD digits is similar to adding 4-bit unsigned binary numbers, except that a correction must be made if a result exceeds 1001. The result is corrected by adding 6. 4+) 5 9 0 1 0 0+) 0 1 0 1 1 0 0 1 9+) 5 1 4 1 0 0 1+) 0 1 0 1 1 1 1 0+) 0 1 1 0 1 0 1 0 0 9+) 8 1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论