1Chapter2NumberSystemsandcodes(数系与编码)NumericData-NumberSystemsandtheirConversions(数值信息——数制及其转换)NonnumericData-Codes(非数值信息——编码)DigitalLogicDesignandApplication(数字逻辑设计及应用)2ReviewofChapter2(第二章内容回顾)Binary,Octal,andHexadecimalNumbers(二进制、八进制、十六进制)PositionalNumberSystem(按位计数制)1pniiirdDDigitalLogicDesignandApplication(数字逻辑设计及应用)3ReviewofChapter2(第二章内容回顾)GeneralPositional-Number-SystemConversion(常用按位计数制的转换)ANumberinanyRadixtoRadix10:Expandingtheformulausingradix-10arithmetic(任意进制数十进制数:利用位权展开)DigitalLogicDesignandApplication(数字逻辑设计及应用)4ReviewofChapter2(第二章内容回顾)GeneralPositional-Number-SystemConversion(常用按位计数制的转换)ANumberinRadix10toanyRadix:RadixMultiplicationorDivision(十进制其它进制:基数乘除法)Note:DecimalFractionPartsConversion[注意:小数部分的转换(误差)]DigitalLogicDesignandApplication(数字逻辑设计及应用)5ReviewofChapter2(第二章内容回顾)AdditionandSubtractionofNondecimalNumbers(非十进制的加法和减法)(Table2-3)进位输入Cin、进位输出Cout、本位和S借位输入Bin、借位输出Bout、本位差DDigitalLogicDesignandApplication(数字逻辑设计及应用)6ReviewofChapter2(第二章内容回顾)RepresentationofNegativeNumbers(负数的表示)Signed-Magnitude[符号-数值(原码)]ComplementNumberSystems(补码数制)Radix–Complement(基数补码)DiminishedRadix–Complement[基数减1补码(基数反码)]DigitalLogicDesignandApplication(数字逻辑设计及应用)7ReviewofChapter2(第二章内容回顾)BinarySigned-Magnitude,Ones’–Complement,andTwo’s–ComplementRepresentation(二进制的原码、反码、补码)正数的原码、反码、补码表示相同负数的原码表示:符号位为1负数的反码表示:符号位不变,其余在原码基础上按位取反在|D|的原码基础上按位取反(包括符号位)负数的补码表示:反码+1DigitalLogicDesignandApplication(数字逻辑设计及应用)82.5.4Two’s–ComplementRepresentation(二进制补码表示法)Ann-bitTwo’s-Complementrangeis(n位二进制补码表示范围):–2n-1~+(2n-1–1)OnlyonerepresentationsofZero(零只有一种表示)ObtainaTwo’s-Complement(二进制补码的求取):Ones’–Complement(反码)+1(为什么??)ExpandingtheSignBit(符号位扩展)DigitalLogicDesignandApplication(数字逻辑设计及应用)92.5RepresentationofNegativeNumbers(负数的表示)Example2.5.2:Writethe8-bitsigned-magnitude,two’s-complementforeachofthesebinarynumbers.(分别写出下面二进制数的8位符号–数值码、补码)(–1101)2(–0.1101)2DigitalLogicDesignandApplication(数字逻辑设计及应用)102.5RepresentationofNegativeNumbers(负数的表示)DigitalLogicDesignandApplication(数字逻辑设计及应用)1、(–1101)22、(–0.1101)21、5位二进制表示:原码反码补码1110110010100112、8位二进制表示:原码反码补码100011011111001011110011[[D]反]反=D[[D]补]补=D112.6Two’s–ComplementAdditionandSubtraction(二进制补码的加法和减法)AdditionRules:Addedbyordinarybinaryaddition(加法:按普通二进制加法相加)P.39SubtractionRules:Takingitstwo’scomplement,thenadd(减法:将减数求补,再相加)DigitalLogicDesignandApplication(数字逻辑设计及应用)122.6Two’s–ComplementAdditionandSubtraction(二进制补码的加法和减法)DigitalLogicDesignandApplication(数字逻辑设计及应用)+20010-31101++5+0101+-5+1011+70111-811000+70111+10001+-4+1100+-6+1010+310011-510111313Adder/SubtractorExample:CalculatorPreviouscalculatorusedseparateadderandsubtractorDIPswitches108-bitregisterCALCLEDsefclkld88800888882x10110wiciAABBSScowo8-bitadder8-bitsubtractor1414Adder/SubtractorExample:CalculatorImprovebyusingadder/subtractor,andtwo’scomplementnumbersDIPswitches108-bitregister8-bitadder/subtractorsubCALCLEDseSABfclkld108888152.6Two’s–ComplementAdditionandSubtraction(二进制补码的加法和减法)Overflow(溢出)如果加法运算产生的和超出了数制表示的范围,则结果发生了溢出(Overflow)。对于二进制补码,加数的符号相同,和的符号与加数的符号不同。(或者,Cin与Cout不同)P.41对于无符号二进制数,若最高有效位上发生进位或借位,就指示结果超出范围。-51011+70111+-6+1010++3+0011-1110101=+5+101010=-6DigitalLogicDesignandApplication(数字逻辑设计及应用)1616OverflowSometimesresultcan’tberepresentedwithgivennumberofbitsEithertoolargemagnitudeofpositiveornegativeEx.4-bittwo’scomplementadditionof0111+0001(7+1=8).But4-bittwo’scomplementcan’trepresentnumber70111+0001=1000WRONGanswer,1000intwo’scomplementis-8,not+8Adder/subtractorshouldindicatewhenoverflowhasoccurred,soresultcanbediscarded1717DetectingOverflow:Method1Fortwo’scomplementnumbers,overflowoccurswhenthetwonumbers’signbitsarethesamebutdifferfromtheresult’ssignbitIfthetwonumbers’signbitsareinitiallydifferent,overflowisimpossibleAddingpositiveandnegativecan’texceedlargestmagnitudepositiveornegative01111000+0001signbitsoverflow(a)11110111+0100overflow(b)10001111+1011nooverflow(c)Ifthenumbers’signbitshavethesamevalue,whichdiffersfromtheresult’ssignbit,overflowhasoccurred.1818DetectingOverflow:Method2Evensimplermethod:Detectdifferencebetweencarry-intosignbitandcarry-outfromsignbit01111111001000+0001overflow(a)11100010111+0100overflow(b)10000001111+1011nooverflow(c)Ifthecarryintothesignbitcolumndiffersfromthecarryoutofthatcolumn,overflowhasoccurred.192.10BinaryCodesforDecimalNumbers(十进制数的二进制编码)DigitalLogicDesignandApplication(数字逻辑设计及应用)Asetofn-bitstringsinwhichdifferentbitstringsRepresentdifferentnumbersorotherthings.(用于表示不同数或其它事件的一组n位二进制码的集合)202.10BinaryCodesforDecimalNumbers(十进制数的二进制编码)Howtorepresenta1-bitDecimalnumberwitha4-bitBinarycode(如何用4位二进制码表示1位十进制码)?——BinaryCodedDecimal(BCD码)DigitalLogicDesignandApplication(数字逻辑设计及应用)212.10BinaryCodesforDecimalNumbers(十进制数的二进制编码)HowtorepresentaNegativeBCDnumber(负的BCD数如何表示)?Signed-MagnitudeRepresentation:Encodingofthesignbitisarbitrary(符号-数值表示:符号位的编码任意)10’s-complement:0000indicatesplus,1001indicatesminus.(十进制补码表示:0000正,1001负)AdditionofBCDDigits(BCD数的加法)P.50DigitalLogicDesignandApplication(数字逻辑设计及应用)22DigitalLogicDesig