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

下载本文档

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

文档简介

Chapter2NumberSystemsandCode重点:1)二进制、八进制和十六进制数的表达及各种数制之间的相互转换;2)符号数的表达及其加、减运算;3)BCD编码和GRAY码。4/21/20231.2.1PositionalNumberSystems1.Decimalnumber

Adecimalnumber1536.79d

digits:0、1、2、3、4、5、6、7、8、9weight:10iradix:10power:i,startfromtheleftofthedecimalpoint,increasebyoneforeachsuccessivepositionfrom0;fromtherightofthedecimalpoint,decreasebyonefrom(-1).powerweightdigitradix2.

AnarbitrarydecimalnumberDwithpdigitsinintegerandndigitsinfractiondp-1dp-2……d1d0.d-1d-2……d-nGeneralexpression:2.Binarynumbersradix:2digits:0、1,alsobecalledbit,weight:2i3.Abinarynumber1011010.1012,:※anarbitrarybinarynumberBbp-1bp-2…b1b0

.b-1…b-n,thegeneralexpressions:Thesumofeachdigitmultipliedbythecorrespondingpoweroftheradixisthebinarynumber’sdecimalvalue.4.3.OthersLSB:LeastSignificantBitMSB:MostSignificantBit

bp-1bp-2…b1b0.b-1…b-nMSBLSB5.2.2OctalandHexadecimalNumbers1.conceptOctalHexadecimalradix816weight8i16idigits0、1、2、3、4、5、6、70、1、2、3、4、5、6、7、8、9、A、B、C、D、E、FGeneralexpression6.Exp3:givethedecimalvalueofthefollowingnumbers.215.78=3AD.8h=2.2-8and2-16number’sConvensionsoctal01234567binarysection000001010011100101110111Table1relationbetweenbinaryandoctal7.hexadecimalbinarysection0000010001200103001140100501016011070111hexadecimalbinarysection8100091001A1010B1011C1100D1101E1110F1111Table2binary-hexadecimalrelations8.(a)binary——octal、hexadecimalconversionsStartingatthebinarypoint,separatethebitsintogroupsof3or4,andreplaceeachgroupwiththecorrespondingoctalorhexadecimaldigit.Iftheleftmostgroupfallshortof3or4bits,then0shouldbeaddedtotheleftoftheMSB;sodotheright。Exp:dothefollowingpositional-number-systemconversion。

1111011010.00112=(?)8=(?)hSolution:=1732.148=3DA.3h9.(b)octal,hexadecimal-binarynumberconversionReplaceeachoctalorhexadecimalwiththecorrespondinggroupof3or4bits.Exp:267.248=(?)296CA.28h=(?)210.2.3generalpositional-number-systemconversionsRadix-r-to-decimalconversion:Eachradix-rnumber’sdigitmultiplybyitsownweight,andaddthem.Exp:512.46=(?)d1、decimal-to-radix-rconversion—integerpartmethods:除基取余Theintegerofapdigitsnumberinradixris:Dividetheformulabyrsuccessively,yieldthesuccessivedigitsoftheintegerofD(radixr)fromtherighttolefttillthequotientis0.11.Exp:371d=(?)2=(?)8=(?)h2、decimal-to-radix-rconversion—fractionpartmethods:乘基取整Thefractionofapdigitsnumberinradixris:Multiplytheformulabyrsuccessively,yieldthesuccessivedigitsofthefractionofD(radixr)fromthelefttorighttilltherequireddigitsd-1

,d-2,……,d-n

areacquired.12.Exp8:0.71875d=(?)2=(?)8=(?)h3、summaryofthepositional-number-systemconversions(1)conversionbetweendecimalandradixr(2)radix-r-to-radix-jconversion(non-decimal)binary-to-octal,binary-to-hexadecimalorreverse,beconverteddirectlyconformingtothesection-replacerules.others,radix-rnumber——decimal——radix-jnumber13.2.4additionandsubtractionofnondecimalnumber1、Rulesofbinaryadditionandsubtraction(1)rulesofadditionS=x+y+CinExp:01001011+10001111=?CinxyCoutS0000000101010010111010001101101101011111initialcarrycarry000011110c14.(2)RulesofBinarySubtractiond=x-y-binExp:11001100-01011100=?binxyboutd0000000111010010110010011101101100011111initialborrowborrow011100000b15.2.additionandsubtractionofoctalandhexadecimaladdition:Iftwodigit’ssumisgreaterthantheradixoneachcolumn,thencarry1tothenextmoresignificantbit.subtraction:Iftheminuendislessthansubtrahend,thenborrow1fromthenextmoresignificantbit.16.2.5RepresentationofNegativeNumbers1、signed-magnituderepresentation

unsignednumbers:justthemagnitudeofanumberisrepresented,no‘+’or‘-’signsymbolbeforethenumber。

signednumbers:’+’or‘-’isaddedtotheleftofthenumber。representationofsignednumber:①signsymbol+numbermagnitude,like+34d、-1102、+1Dh、…

17.②inbinarynumber,signbit+magnitudeTheMSBofabitstringisusedasthesignbit:0—“+”,1—“-”thistypeofsignedbinarynumberiscalledSignedMagnitude(S-M码,或原码)。比如,+11101=011101-1011=1101118.③TherangeofS-M’srepresentablenumbers.ann-bitS-MnumberB:

bn-1bn-2…b1b0Itsrangeis:-(2n-1-1)~+(2n-1-1)

Includetwozero:-0and+0Exp:findtheS-Mofthefollowingsignednumbers。Howtorepresentbyusing8-bitS-M.+11101,-1011,+18,-18④thefaultofS-Mwhichisusedinarithmeticaloperation:itcan’tbecalculateddirectly.符号位数值19.2、ComplementNumberSystemradixcomplement(基数补码数制)diminishedradix-complement(基数减1补码数制)Ann-digitnumberDinradixr:D=dn-1……d1d0,①radix-complement②diminishedradix-complement(也称基数反码)Relationbetweenthesetwo:Table2-4,2-5(P.36)showssomer’sand(r-1)s’complement.20.3.Two’s-complementRepresentation

Two'scomplementisamethodforrepresentingsignedintegersasbinarynumbers.n-bitbinarynumberB=bn-1……b1b0,thetwo’scomplementis:B

2’s=2n-B

forExp.,8-bitbinarynumber two’scomplement 00000000 28-0=00000000 00000001 28-1=11111111 00000010 28-10=11111110 …… …… 11111111 0000000121.Definethesetwo’scomplementassignednumber,theMSBisservedassignbit。

MSB=0,positivenumberMSB=1,negativenumberweightofthesignbit:MSB=0,weight+2n-1

MSB=1,weignt-2n-1Rangeofthevalue:positive—0~+(2n-1-1);

negative—(-2n-1)~-1。Onlyonezerointwo’scomplement.22.two’scomplementnumberandtheirdecimalequivalent2’scomplementdecimal00000000000000001+1…………01111111+12710000000-12810000001-127…………11111110-211111111-123.2’s-complementdecimalequivalentS-M000000000000000001000000000000001+100000001……………..01111111+1270111111110000000-128-10000001-12711111111………………11111110-21000001011111111-11000000124.propertysignbit=0,S-Mandtwo’s-complementhavethesamedecimalvalue;signbit=1,S-Mandtwo’s-complementhavedifferentdecimalvalue。Howtofindthetwo’s-complementrepresentationofanegativedecimalnumber?25.Decimalequivalent4-bits2’scomplement-81000-71001-61010-51011-41100-31101-21110-11111ItsoriginalbinarynumberDecimalequivalent1000801117011060101501004001130010200011互为补数Samevalue,buthasoppositesignsymbol26.So,tocalculatethe2'scomplementofannegativeinteger,invertthen-bitbinaryequivalentofthegivennumbermagnitudebitbybit,andthenadd1totheLSB.Exp:calculatethe2’scomplementof(+65)and(-65d)in8-bitform.Solution:+6501000001-65binaryequivalentof65is01000001,invertbitbybit10111110add11011111127.Ann-bitbinarynumberB=bn-1……b1b0,theones’-complementis:B

1s’=2n-1-BItisalsothemethodofrepresentingsignedbinarynumbers.MSB=0,positive,weight+(2n-1-1)MSB=1,negative,weight-(2n-1-1)。Rangeofrepresentablenumbers:negative—-(2n-1-1)~-0positive—+0~(2n-1-1)4.Ones’-complementRepresentation28.1s’-complement’spropertyN-bitpositiveintegersarerepresentedinthesamewayasn-bitsign-magnitudenotation.Theones’-complementofann-bitnegativeintegernumberisobtainedbycomplementingeachoneofthebits(then-bitbinarynumber),i.e.,a1isreplacedbya0,anda0isreplacedbya1.Exp.8-bit1s’-complementofthenumber.+18d=00010010-18d=1'scomplementof18=1110110129.decimalS-M2’scomp.1s’comp.-1100111111110-2101011101101-3101111011100-4110011001011-5110110111010-6111010101001-7111110011000-8-1000-decimalS-M2’scomp.1s’comp.7011101110111601100110011050101010101014010001000100300110011001120010001000101000100010001000001000000011110000返回Fromtheleastnumbertobiggestnumber,2’scomp.and1s’comp.aresuccessiveincreasedby1.SummaryofS-M,2’scomp.,1s’comp.30.Allofthesethreeareusedtorepresentsignedintegernumberinbinarysystem.Comparingoftherepresentingrangeofthevalue

Representationsofpositiveintegeraresame;buttherepresentationsofnegativeintegeraredifferentatall.S-M2’scomp.1s’comp.positive+0~(2n-1-1)+0~(2n-1-1)+0~(2n-1-1)negative-(2n-1-1)~-0(-2n-1)~-1-(2n-1-1)~-031.Calculatesignedinteger’sS-M,2’s-comp.,1s’-comp.①positivesignednumber:convertthegivennumberintothewantedn-bitbinaryequivalent.②negativesignednumber:firstconvertthenumberinton-bitbinaryequivalent,

S-M—letMSB=1;

1s’-complement—invertthen-bitbinaryequivalentbitbybit,getthen-bit1s’-comp.;

2’s-complement—add1totheLSBofthen-bit1s’-complementofthegivennumberExp13:FindingtheS-M,2’s-comp,1s’-compofthefollowingsignednumberin8-bit。+60,-60,+10010,-110132.5.SignextensionWhenweconvertann-bit2’scomplementnumberXintoanm-bitone:(a)ifm>n,append(m-n)copiesofX’ssignbittotheleftofX;(b)ifm<n,discardX’s(n-m)leftmostbit。Sodoto1s’-complement.33.2.6Two’s-complementAdditionandSubtraction1、RulesTwooperandsaddorsubtractdirectly

Exp:

3+3,4+(-5),7-3,1-6,符号数表格34.2.AgraphicalviewModular:thebiggestnumberofquantitiesthatan-bitsystemcanrepresentis2n.Modularoperation:mMOD2n=m-i·2n(i=int())

Exp:18MOD16=276543210-1-2-3-4-5-6-7-80111011001010100001100100001000011111110110111001011101010011000+235.3.overflowIfanadditionoperationproducesaresultthatexceedstherangeofthenumbersystem,overflowissaidtooccur.thatis,ifresult>+(2n-1-1),or<-(2n-1),overflowisoccurred.Detectingofoverflow:

Anadditionoverflowsiftheaddends’signsarethesamebutthesum’ssignisdifferentfromtheaddends’.Exp:judgewhethertheresultoftheadditionoverflowornot。11111101+1000000136.4.Subtractionrulesm-n=m+(2n-n)Negatethesubtrahendbytakingits2’scomplement,andthenaddittotheminuendusingthenormalrulesforaddition.

2’s-comp.ofn76543210-1-2-3-4-5-6-7-80111011001010100001100100001000011111110110111001011101010011000-2+1437.Exp:8-bit2’s-comp.38.5.Two’s-complementandUnsignedBinaryNumbersWhenn-bitbinarynumbersaretakenforunsignednumber,therulesofadditionandsubtractionareassameasthe2’s-complement.Iftheresultofadditionoperationexceedtherangeofn-bitsystem,acarryisproducedtotheleftmoresignificantbit.39.2.10BinaryCodesforDecimalNumbersEmphasis:BCD,excess-3code:asetofn-bitinwhichdifferentbitstringsrepresentdifferentnumbersofotherthingsiscalledacode.codeword:aparticularcombinationofnbit-values.1、BCDcodethedigits0~9areencodedby4-bitunsignedbinaryrepresentations,0000through1001.andthewords1010~1111arenotused.(invalidcodeword)40.BCD’spropertyBCDisweightedcode,theweightsforthebitsfromlefttorightis:23、22、21、20。alsocalled8421BCD。(1)representingnumbersbyBCDlike,11d,BCD—00010001 256d, BCD–001001010110(2)PackedBCDtwo-digits-per-bytedecimaldigits8421BCD00000100012001030011401005010160110701118100091001Donotdiscardthese041.(3)AdditionwithBCDbesimilarto4-bitunsignedbinarynumberaddition.Butacorrectionmustbemadeifthesumexceeds1001if,sum>1001,thenadd0110totheresult。Exp.:>1001makeacorrection42.2.OtherdecimalcodesP.49table2-9,Excess-3code:th

温馨提示

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

评论

0/150

提交评论