Upload
vbpanchal
View
220
Download
0
Embed Size (px)
Citation preview
7/27/2019 Lect 18 - Binary Addition and Subtraction
1/18
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU1
Binary additon &
subtraction
7/27/2019 Lect 18 - Binary Addition and Subtraction
2/18
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 2
Class 18Subtraction Binary Addition and Subtraction
Subtraction circuits
Incrementer, Decrementer
Material from section 4-3 and 4-4 of text
7/27/2019 Lect 18 - Binary Addition and Subtraction
3/18
Binary Subtraction Have previously looked at the subtraction operation. A
quick review.
Just like subtraction in any other base Minuend 10110
Subtrahand - 10010
Difference 00100
And when a borrow is needed. Note that the borrow givesus 2 in the current bit position.
.
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 3
7/27/2019 Lect 18 - Binary Addition and Subtraction
4/18
And a full example And more ripple -
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 4
7/27/2019 Lect 18 - Binary Addition and Subtraction
5/18
In General When there is no borrow into the msb position,
then the subtrahend in not larger than the
minuend and the result is positive and correct.
If a borrow into the msb does occur, then thesubtrahend is larger than the minuend. This was
seen back in lecture 2.
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 5
7/27/2019 Lect 18 - Binary Addition and Subtraction
6/18
Consider Now do the operation 46
Correct difference is -2 or -0010
Different because 2n was brought in and made
the operation M-N+2n
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 6
7/27/2019 Lect 18 - Binary Addition and Subtraction
7/18
Desired Actual desired magnitude is N-M
To get this need to do 2n(M-N+2)= N-M
Doing the subtraction from 2n gives the
correct result.
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 7
7/27/2019 Lect 18 - Binary Addition and Subtraction
8/18
Twos compliment But how do you represent a minus sign
electronically in a computer?
How can you represent it such that arithmetic
operations are manageable? There are two types of compliments for each
number base system. Have the rs complement
Have the (r-1)s complement For base 2 have 2s complement and
1s complement
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 8
7/27/2019 Lect 18 - Binary Addition and Subtraction
9/18
1s Complement 1s complement of N is defined as (2n -1)-N.
If n=4 have (2n -1) being 1 0000 - 1 = 1111
So for n=4 would subtract any 4-bit binarynumber from 1111.
This is just inverting each bit.
Example: 1s compliment of 1011001
is 0100110
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 9
7/27/2019 Lect 18 - Binary Addition and Subtraction
10/18
2s complement The 2s complement is defined as 2n-N
Can be done by subtraction of N from 2n or
adding 1 to the 1s complement of a number. For 6 = 0110
The 1s complement is 1001
The 2s complement is 1010
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 10
7/27/2019 Lect 18 - Binary Addition and Subtraction
11/18
Operation with 2s complement
Add 4 and -6
Will use the 2s complement of-6 or 1010
4 0100
-6 1010
1110
And taking the 2s complement of 1110 get0001 + 1 = 0010
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 11
7/27/2019 Lect 18 - Binary Addition and Subtraction
12/18
A 2s complement table for 4 bits
Listing the
values
represented.
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 12
7/27/2019 Lect 18 - Binary Addition and Subtraction
13/18
A circuit that does +/-
A general adder subtractor
OP=0 for addition/ =1 for subtraction
9/15/09 - L15 Decoders,Multiplexers Copyright 2009 - Joanne DeGroat, ECE, OSU 13
7/27/2019 Lect 18 - Binary Addition and Subtraction
14/18
Another number format
Signed magnitude
use the MSB to
indicate the sign. Theremaining bits
indicate the
magnitude.
9/15/09 - L15 Decoders,
Multiplexers
Copyright 2009 - Joanne DeGroat, ECE, OSU 14
7/27/2019 Lect 18 - Binary Addition and Subtraction
15/18
Overflow
When adding 2 n-bit numbers it is possilbe toget a n+1 bit result if there is a carry out.
On paper it is easy just add another bit. In 2s complement add a msb 0 for a positive
or a msb 1 for a negative.
In a computer the number of bits that can beused is fixed.
9/15/09 - L15 Decoders,
Multiplexers
Copyright 2009 - Joanne DeGroat, ECE, OSU 15
7/27/2019 Lect 18 - Binary Addition and Subtraction
16/18
Overflow indication.
In 8-bit 2s complement notation the range
that can be represented is -127 to +127.
Then the operation to add +70 to +80 is Carries 0 1
+70 0 100 0110
+80 0 101 0000
+150 1 001 0110
Also look at the addition of -70 and -809/15/09 - L15 Decoders,
Multiplexers
Copyright 2009 - Joanne DeGroat, ECE, OSU 16
7/27/2019 Lect 18 - Binary Addition and Subtraction
17/18
The other addition The addition of -70 and -80
Carries 1 0
-70 1 011 1010
-80 1 011 0000
-150 0 110 1010
The ruleif the carry into the msb position differs fromthe carry out from the msb position then an overflow hasoccurred.
The circuit
.
9/15/09 - L15 Decoders,
Multiplexers
Copyright 2009 - Joanne DeGroat, ECE, OSU 17
7/27/2019 Lect 18 - Binary Addition and Subtraction
18/18
Class 18 assignment
Covered sections 4-3 through 4-4
Problems for hand in
none Problems for practice
4-3, 4, 5, 6, 7, 8,16
Reading for next class: sections 5-1, 5-2
9/15/09 - L15 Decoders,
Multiplexers
Copyright 2009 - Joanne DeGroat, ECE, OSU 18