Slides for Lecture 5
ENEL 353: Digital Circuits — Fall 2013 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 18 September, 2013 ENEL 353 F13 Section 02 Slides for Lecture 5 slide 2/19Previous Lecture
◮ drawbacks of sign/magnitude representation of signed integers ◮ two’s complement representation of signed integers ENEL 353 F13 Section 02 Slides for Lecture 5 slide 3/19Today’s Lecture
◮ ranges for two’s-complement systems ◮ overflow in two’s-complement addition ◮ BCD (binary coded decimal) codes for decimal digits ◮ Gray codes Related reading in Harris & Harris: Section 1.4.6 for two’s-complement concepts and facts. Harris & Harris do not really cover BCD or Gray codes—there are very brief descriptions on pages 258 (BCD) and 76 (Gray codes). ENEL 353 F13 Section 02 Slides for Lecture 5 slide 4/19Sum of a finite geometric series
A fact from mathematics: For any r, k−1- i=0
Ranges for two’s-complement systems
For an n-bit two’s-complement system, the minimum value is −(2n−1) and the maximum value is 2n−1 − 1. Here are some example ranges for various choices of n: width n minimum value maximum value 4 −23 = −8 23 − 1 = 7 8 ? ? 16 ? ? 32 −2,147,483,648 2,147,483,647 The last row in the table gives the range of a typical C or C++ int type. ENEL 353 F13 Section 02 Slides for Lecture 5 slide 6/19Overflow in two’s-complement addition (often called “signed overflow”)
What is the largest number in a 6-bit two’s-complement system? So, something will go wrong if we try to add 2310 + 2310 in 6-bit two’s complement. Let’s see what happens . . . ENEL 353 F13 Section 02 Slides for Lecture 5 slide 7/19Facts about overflow in two’s-complement addition
Overflow cannot happen when two numbers with opposite signs are added. When two numbers with the same sign are added, overflow has occurred if and only if the sign of the result is- bviously wrong.
Unsigned overflow vs. signed overflow in binary addition
Unsigned overflow and signed overflow are NOT THE SAME THING! With an n-bit adder you can have neither, one but not the- ther, or both.
Unsigned overflow vs. signed overflow in binary addition: 4-bit examples
In addition of 1100 and 1101 is there unsigned overflow? Is there signed overflow? What about in each of these three additions? carry: 1 0 0 0 0 1 1 0 0 + 1 0 1 0 0 1 1 0 carry: 1 1 1 1 0 1 1 1 1 + 0 0 0 1 0 0 0 0 carry: 0 1 1 0 0 0 1 1 0 + 0 0 1 1 1 0 0 1