binary arithmetics & operations · with the same number of digits. ... (n-1)-bit binary paern...
TRANSCRIPT
BinaryArithmetics&Operations
BinaryArithmetic• Addi$on• Subtrac$on• Mul$plica$on• Division
Operations• Complement’sofanumber(DiscussedinBinaryOpera$ons)• Genera$ngBinaryCodedDecimalsandExcess-3codes• ShiFOpera$ons• Arithme$cShiFLeF• Arithme$cShiFRight• LogicalShiFLeF• LogicalShiFRight
• Floa$ngPointRepresenta$on
BinaryAddition• 1+1=0plusacarryof1• 0+1=1• 1+0=1• 0+0=0
BinaryAdditionClassExample:Addfollowingtwobinarynumbers:
101001100111
BinarySubtraction• 0–0=0• 1–0=1• 1–1=0• 0–1=1withborrowof1
BinarySubtraction• Toperformasubtrac$on• Alignthetwonumbersasyouwouldindecimalsubtrac$on.• Appendleadingzerosifnecessarytorepresentbothnumberswiththesamenumberofdigits.
• Applytwo'scomplementtothesecondterm• Addthecomplementednumbertothefirstterm.• Thesuminthepreviousstepshouldhaveonemoredigitthanyoustartedwith
Complementsofanumber• Complementsareusedindigitalcomputersforsimplifying
thesubtrac$onopera$onandforlogicalmanipula$ons• 2typesforeachbase-rsystem
1) r’scomplement(Radixcomplement)2) (r-1)’scomplement(DiminishedradixComplement)
Complementsofanumber• Referredtoasr’scomplement• Ther’scomplementofNisobtainedas(rn)-Nwhere r=baseorradix n=numberofdigits N=number
DiminishedRadixComplement• Inthebinarynumbersystemr=2thenr-1=1sothe1’scomplementofNis(2n-1)-N
• Whenabinarydigitissubtractedfrom1,theonlypossibili$esare1-0=1or1-1=0
Therefore,1’scomplementofabinarynumeralisformedbychanging1’sto0’sand0’sto1’s.
Complementsofanumber• Givethe10’scomplementforthefollowingnumber a.583978 b.5498
Solu$on: a.N=583978 n=6 106-583978 1,000,000–583978=416022 b.N=5498 n=4 104-5498 10,000–5498=4502
One’sComplement• Themostsignificantbit(msb)isthesignbit,withvalueof0represen$ngposi$veintegersand1represen$ngnega$veintegers.• Theremainingn-1bitsrepresentsthemagnitudeoftheinteger,asfollows:• forposi$veintegers,theabsolutevalueoftheintegerisequalto"themagnitudeofthe(n-1)-bitbinarypadern".• fornega$veintegers,theabsolutevalueoftheintegerisequalto"themagnitudeofthecomplement(inverse)ofthe(n-1)-bitbinarypadern"(hencecalled1'scomplement).
One’sComplement• Example1:Supposethatn=8andthebinaryrepresenta$on01000001.Signbitis0⇒posi$veAbsolutevalueis1000001=65Hence,theintegeris+65• Example2:Supposethatn=8andthebinaryrepresenta$on10000001.Signbitis1⇒nega$veAbsolutevalueisthecomplementof0000001B,i.e.,1111110B=126Hence,theintegeris-126
Two’sComplement• Again,themostsignificantbit(msb)isthesignbit,withvalueof0represen$ngposi$veintegersand1represen$ngnega$veintegers.• Theremainingn-1bitsrepresentsthemagnitudeoftheinteger,asfollows:• forposi$veintegers,theabsolutevalueoftheintegerisequalto"themagnitudeofthe(n-1)-bitbinarypadern".• fornega$veintegers,theabsolutevalueoftheintegerisequalto"themagnitudeofthecomplementofthe(n-1)-bitbinarypadernplusone"(hencecalled2'scomplement).
Two’sComplement• Example1:Supposethatn=8andthebinaryrepresenta$on00000000.Signbitis0⇒posi$veAbsolutevalueis0000000=0Hence,theintegeris+0• Example2:Supposethatn=8andthebinaryrepresenta$on11111111.Signbitis1⇒nega$veAbsolutevalueisthecomplementof1111111Bplus1,i.e.,0000000+1=1Hence,theintegeris-1
ExampleSubtractionBinarySubtractionStep1
BinarySubtractionStep2
BinarySubtractionStep3
BinarySubtractionStep4
BinarySubtractionStep5
BinaryMultiplication
• 0x0=0• 0x1=0• 1x0=0• 1x1=1
BinaryMultiplication
• ClassExample• Mul$plyfollowingtwobinarynumbersanddiscusstheresult:• 101• 100
BinaryOperationsBinaryCodes(BCD&Excess-3)DecimalDigit (BCD)
8421Excess-3
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
In a digital system, it may sometimes represent a binary number, other times some other discrete quantity of information
BinaryOperations• ShiFopera$ons• Itistheopera$onofshiFingabitstringtotherightorleF.
ArithmeticShiftArithme$cShiFisanopera$onofshiFingabitstring,exceptforthesignbit.Example:ShiFbitsby1
ALS 1 1 1 1 1 0 1 0 1 1 1 1 0 1 0 0
ARS 1 1 1 1 1 0 1 0 1 1 1 1 1 1 0 1
Sign bit
Insert a zero in the vacated spot
Sign bit overflow overflow
LogicalShift
Floatingpointrepresentation• Arealnumberisrepresentedinexponen$alform(a=+-mxre)
1bit 8bits 23bits(singleprecision)
0 10000100 11010000000000000000000
Sign Exponent Man$ssa
Radix point
Floatingpointrepresentation• Steps• Indicatenumberwheternega$veorposi$ve• NormalizeTheNumber(1.10000100101000)• FindExponentpart(powerofn)• Thenputinthefollowingform:
• Becarefulabouttheexponentpart(E-127)• ClassExample
1bit 8bits 23bits(singleprecision)
0 10000100 11010000000000000000000
Sign Exponent Man$ssa
Floatingpointrepresentation