slides for lecture 4
play

Slides for Lecture 4 ENEL 353: Digital Circuits Fall 2013 Term - PowerPoint PPT Presentation

Slides for Lecture 4 ENEL 353: Digital Circuits Fall 2013 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 16 September, 2013 slide 2/17 ENEL 353 F13 Section 02


  1. Slides for Lecture 4 ENEL 353: Digital Circuits — Fall 2013 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 16 September, 2013

  2. slide 2/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Previous Lecture ◮ a little more about binary, octal, and hexadecimal numbers ◮ introduction to signed and unsigned number systems ◮ unsigned binary integer addition ◮ sign/magnitude representation of signed integers

  3. slide 3/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Today’s Lecture ◮ drawbacks of sign/magnitude representation of signed integers ◮ two’s complement representation of signed integers Related reading in Harris & Harris: Section 1.4.6.

  4. slide 4/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Some important ideas from the previous lecture Number systems in digital circuits and computer systems usually have a fixed quantity of bits available to represent a number; this quantity is called the width of the number system. Number systems that allow negative numbers, zero, and positive numbers are called signed number systems. sign/magnitude is one way to set up a system of signed integers.

  5. slide 5/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Sign/magnitude numbers (last slide from previous lecture) We use sign/magnitude in daily life with decimal numbers, such as +5, − 37, 44. (If the sign is left out, we assume that it’s +.) For binary numbers, we can use 1 to stand for − and 0 to stand for +. Let’s look at some examples of binary sign/magnitude representation. (Done in previous lecture.) A new question for today: What is the range of an n-bit sign/magnitude system?

  6. slide 6/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Drawbacks of sign/magnitude systems It’s annoying that zero has two different representations : 000 · · · 00 and 100 · · · 00. Ideally, two numbers should be equal only if they have identical bit patterns. Complicated logic is needed to add two numbers that have opposite signs.

  7. slide 7/17 ENEL 353 F13 Section 02 Slides for Lecture 4 What makes a number format good? In digital systems design it is important that arithmetic circuits are small and efficient . It is not important that numbers be easy for humans to read! By these criteria, sign/magnitude is not a winning format—circuits for the common operations of comparison and addition are more complicated than necessary.

  8. slide 8/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Bit numbering, the MSB, and the LSB Each bit in an n -bit pattern can be given a number to identify the position of the bit within the pattern. The range of bit numbers runs from 0 up to and including n − 1. Bit n − 1, on the far left, is called the MSB (most significant bit). Bit 0, on the far right, is called the LSB (least significant bit). Let’s draw a diagram. For the eight-bit pattern 01110101, what are the bit numbers and values of the MSB and LSB? What is the value of bit 4?

  9. slide 9/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Two’s complement systems for signed integers Two’s complement is way, way more widely used than sign/magnitude or any other method for representing signed integers. Examples: ◮ With current processor chips, operating systems, and C and C ++ compilers, the int type is almost certain to be 32-bit two’s-complement. ◮ In Java programming, the int type is guaranteed to be 32-bit two’s-complement, and the long type is guaranteed to be 64-bit two’s-complement.

  10. slide 10/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Two’s complement systems: Zero and positive numbers In two’s complement, zero and positive numbers are just like sign/magnitude: the MSB is 0, and all the other bits are used for the magnitude. What are the 5-bit two’s-complement representations of 0 and 9 10 ?

  11. slide 11/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Two’s complement systems: Negative numbers Suppose that a is a positive n -bit number. Then the bit pattern for the n -bit two’s-complement representation of − a is the same as the bit pattern for the unsigned number 2 n − a . Example: What is the 5-bit two’s complement representation of − 10 10 ? Let’s compare 5-bit two’s-complement and sign/magnitude rep’s of +10 10 and − 10 10 .

  12. slide 12/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Two’s complement systems: Finding the n -bit pattern for a negative number The algorithm is: 1. Get the n -bit binary representation for the magnitude of the number. 2. Invert (in other words, complement ) each bit. Each 0 changes to 1, and each 1 changes to 0. 3. Add 1 to the result using n -bit unsigned addition. (That implies ignoring the carry out of the MSB.) Let’s demonstrate for the 5-bit rep of − 10 10 . What happens if we try to find the 5-bit rep of − 0 (“negative zero”)?

  13. slide 13/17 ENEL 353 F13 Section 02 Slides for Lecture 4 6-bit two’s complement examples What are the 6-bit two’s-complement representations of − 17 10 and 23 10 ? Attention: A width must be specified. It does not make sense to ask, “What are the two’s-complement representations of − 17 10 and 23 10 ?” without any particular width in mind.

  14. slide 14/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Two’s-complement negation Review from two slides back . . . 1. Get the n -bit binary representation for the magnitude of the number. 2. Invert (in other words, complement ) each bit. Each 0 changes to 1, and each 1 changes to 0. 3. Add 1 to the result using n -bit unsigned addition. (That implies ignoring the carry out of the MSB.) Steps 2 and 3 together are called two’s-complement negation . Let’s try two’s-complement negation starting with a negative number.

  15. slide 15/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Two good things (among many) about two’s complement (1) There is only one way to represent zero, and it’s obvious: all bits are 0. (2) Perhaps surprising, but true and extremely useful : An unsigned binary adder circuit will correctly perform two’s-complement addition! Let’s demonstrate this with our 6-bit two’s-complement bit patterns for − 17 10 and 23 10 .

  16. slide 16/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Why does a circuit for unsigned addition also work for two’s-complement addition? It might seem like we’ve picked a system more or less at random for representing negative numbers. Therefore it might seem like a fluky accident that an adder designed for unsigned numbers will handle negative numbers correctly! In fact, straightforward but time-consuming mathematics proves why this is true. Your textbook and lectures both skip the proofs!

  17. slide 17/17 ENEL 353 F13 Section 02 Slides for Lecture 4 Next 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 the two’s-complement stuff. Harris & Harris do not really cover BCD or Gray codes—there are very brief descriptions on pages 258 (BCD) and 76 (Gray codes).

Recommend


More recommend