cse 111 binary arithmetic thanks to dr. schindler
TRANSCRIPT
![Page 1: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/1.jpg)
CSE 111
Binary Arithmetic
Thanks to Dr. Schindler
![Page 2: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/2.jpg)
Binary Addition
Addition Table
Using the above table, proceed as with base ten.
0
1
0
1
1
0
+ 0 1
Carry1
![Page 3: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/3.jpg)
Binary Addition
ExampleConsider 1410 + 910 using binary addition
Sum = 101112 = 2310
1 1 1 0+ 1 0 0 1
1 0 1 1 1
1
![Page 4: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/4.jpg)
Subtraction with 2’s Complement
Procedure (M-N)Express minuend, M, and subtrahend, N, with same
number of integer bitsAdd minuend, M, to 2’s complement of subtrahend,
N.If an end carry occurs, discard it.
Indicates positive result
If not, the result is a negative value represented in r’s complement notation.
![Page 5: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/5.jpg)
Subtraction with 2’s Complement
Example #1Consider 8110 - 4510 using 2's complement and 8 bits
10100012 - 001011012
2's complement of 4510 = 110100112
001010001 + 11010011 = 100100100End carry occursDiscard end carryDifference = 001001002 = 3610
![Page 6: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/6.jpg)
Subtraction with 2’s Complement
Example #2Consider 5310 - 6010 using 2's complement and 8 bits
001101012 - 001111002 2's complement of 6010 = 110001002
00110101 + 11000100 = 11111001No end carryResult (111110012) is in 2's complement notation
Difference = 111110012 = -710
![Page 7: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/7.jpg)
Overflow
An overflow occurs when the result of an arithmetic operation falls outside the available range that can be stored.
![Page 8: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/8.jpg)
Overflow
Detection of overflow for addition of signed numbersCarries into & out of MSB (sign bit) differTwo positive numbers added & negative result is
obtainedTwo negative numbers added & a positive result is
obtained
Note that overflow cannot occur if two numbers of differing signs are added
![Page 9: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/9.jpg)
Number Ranges
Unsigned Numbers0 2n-1Example
8 Bit0255
16 Bit0 65,535
32 Bit04,294,967,295
64 Bit0 18,446,744,073,709,599,999
![Page 10: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/10.jpg)
Number Ranges
Signed Numbers in Two’s Complement Notation-2n-1 2n-1-1Example
8 Bit-128127
16 Bit32,76832,767
32 Bit-2,147,483,6482,147,483,647
64 Bit-9,223,372,036,854,780,000 9,223,372,036,854,779,999
![Page 11: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/11.jpg)
Overcoming Overflow
If overflow occurs, how can we overcome it?Additional bits are required
![Page 12: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/12.jpg)
Overcoming Overflow
The ProblemAdding more bits is fine for an unsigned number,
but how about a signed number?Example - Unsigned
Represent the unsigned number 38 as an 8-bit number00100110
Extend it to 16-bits0000000000100110
Example - SignedRepresent the signed number 38 as an 8-bit number
11011010
Extend it to 16-bits and put 0’s in the new bit positions 0000000011011010The problem is that this is not -38, it is +218
To preserve the sign and magnitude, the sign must be replicated in the new positions1111111111011010
![Page 13: CSE 111 Binary Arithmetic Thanks to Dr. Schindler](https://reader035.vdocuments.net/reader035/viewer/2022080914/56649ceb5503460f949b614e/html5/thumbnails/13.jpg)
References
J. Glenn Brookshear, Computer Science - An Overview, 11th edition, Addison-Wesley as an imprint of Pearson, 2012
Daniel Hillis, The Pattern on the Stone, Basic Books (Perseus Books Group), 1998
M. Morris Mano and Charles R. Kime, Logic and Computer Design Fundamentals, Prentice Hall, Inc., 2000
Victor P. Nelson, H. Troy Nagle, Bill D. Carroll, and J. David Irwin, Digital Logic Circuit Analysis and Design, Prentice Hall, Inc., 1995
Donald D. Givone, Digital Principles and Design, McGraw-Hill, 2003