Professional Documents
Culture Documents
ECE 171 Digital Circuits: Prof. Mark G. Faust Maseeh College of Engineering and Computer Science
ECE 171 Digital Circuits: Prof. Mark G. Faust Maseeh College of Engineering and Computer Science
ECE 171 Digital Circuits: Prof. Mark G. Faust Maseeh College of Engineering and Computer Science
Lecture2
Topics
BinaryArithmetic(Unsignedbinaryoperands) Signed i dnumber b representations i
SignedMagnitude DiminishedRadixComplement(OnesComplement) RadixComplement(TwosComplement)
BinaryArithmeticRevisitedandOverflow SignExtension
BinaryArithmetic
Rulesforcarrysameasindecimal
1 carry
0 + 0 0
0 + 1 1
1 + 0 1
1 + 1 10
UnsignedBinary(UB)Addition
Examples(4bitword) 2+6
11
11+6
1 11
2 +6 8
11 +6 17
17>241
4
Overflow(Underflow)
Definition: Resultofanarithmeticoperation p istoolarge g (or ( small) )tobe representedinnumberofbitsavailable Detection: Varieswiththerepresentation.Forunsignedbinary,its determinedbyacarryoutoftheMSB
1 11
11 8bitoperands
SignedNumbers
Havebeenassumingnonnegativenumbers
Unsigned g Binary y(UB) ( )
Severalrepresentationsforsignednumbers
SignMagnitude(SM) DiminishedRadixComplement(DRC)
1sComplement
RadixComplement(RC)
2sComplement
6
SignMagnitude
MSBfunctionsassignbit 0=positive 1=negative Rangeofnumbers: (2n1 1)to+(2 (2n1 1)
n=6
Tworepresentationsfor0 Negativeformedby complementingsignbit 1510=001111SM 1510=101111SM 010100SM =2010 110100SM =2010
7
DiminishedRadixComplement(DRC)
CalledOnesComplement MSBindicatessign 0=positive 1=negative (b notasignbit!) (but b !) Rangeofnumbers: (2n1 1)to+(2n1 1) Tworepresentationsfor0 Negative egat eformed o edbyco complementing p e e t g e entire t eword od (calledtakingtheonescomplement) 1510=001111DRC 1510=110000DRC 010100DRC =2010 101011DRC =2010
8
RadixComplement(RC)
CalledTwosComplement g MSBindicatessign 0=positive 1=negative (butnotasignbit) Rangeofnumbers: (2n1)to+(2n1 1) Onlyonerepresentationfor0 Negativeformedbycomplementingentireword andadding1(calledtakingthetwoscomplement) 1510=001111RC 1510=110001RC 010100RC =2010 101100RC =2010
9
TwosComplement SpecialCases
Example:TakeTwosComplement(RC) of0000(010)
0000
1 1 1
1111 +1 0000
Complement AddOne
IgnorecarryoutofMSB
10
TwosComplement SpecialCases
Example:TakeTwosComplement(RC) of1000(810)(mostnegative)
1000
1 1 1
0111 +1 1000
Complement AddOne
Cantrepresent abs(mostnegativenumber)
11
ConversionsofSigned Representations
Fromdecimal
Representthe h absolute b l value l of fthe h number b inUB Usethecorrectnumberofbits(addleading0s) Ifthedecimalnumberisnegative,usetheappropriateruletonegate therepresentation
S/M complementthesignbit DRC(onescomplement) complementeverybit RC(twoscomplement) complementeverybit,add1
To T decimal d i l
Ifnumberis+,convertfromUBtodecimal(done!) Ifnumberis useappropriateruletonegateit(obtainitsabsolute value)
S/M complementthesignbit DRC(onescomplement) complementeverybit RC(twoscomplement) complementeverybit,add1
12
WhydoweuseRC (TwosComplement)?
Onlyonerepresentationforzero SimplifiedAddition
SignMagnitudeAddition
Mustconsidertwooperandswithoutsignbits Ifsignbitssame:performadd,checkoverflow Ifsignbitsdifferent:subtract(twocases)
+Aand B A B Aand+B B A
Generatecorrectsignbitforsum
RadixComplement(TwosComplement)Addition
Justadd!
SimpleSubtraction
Doneviaaddition
A + B A B=A+(B) Caution:Canttakenegativeofmostnegativenumber
13
BinaryArithmetic
UnsignedBinary(UB) SignedBinary(SB) DiminishedRadixComplement(DRC)
1scomplement
Rarely used
RadixComplement(RC)
2scomplement
14
RadixComplement(RC)orTwos ComplementAddition
Examples(4bitword) 7+(2)
1 11
5+(7)
1
5 +(7) (2)
15
RadixComplement(RC)orTwos ComplementAddition
Examples(4bitword) 7+(2)
1
CarryandOverflow
Isthisanoverflowcondition?
1 1 1011 00
CarryandOverflow
Isthisanoverflowcondition?
1 1 1011 00
CarryandOverflow RadixComplement(2sComplement)
Consider:
Positive+Negative Neveroverflow Negative+Negative Overflowpossible Positive+Positive Overflowpossible
DetectingOverflow:
Ifsigns g ofaddendsaresameandsign g ofsumis different EquivalenttoCSBP CSBP+1
19
CarryandOverflow
CSBP+1 CSBP 1 1 1011 00 C Carry SBP SignBitPosition
20
RadixComplement(RC)Addition
Examples(4bitword) 7+(2)
CSBP+1 CSBP 1 000
CSBP+1 CSBP
9< (23)
21
SignExtension
Whathappenswhenyoumoveanumberfromasmallerword sizetoalargerone? UB
00000011 (3) 0000000000000011 (3)
S/M
00000011 (3) 0000000000000011 (3)
RC(2scomplement)
00000011 (3) 0000000000000011 (3)
11111101 (3)
1111111111111101 (3)
22