previous lecture today s lecture slides for lecture 3
play

Previous Lecture Todays Lecture Slides for Lecture 3 ENEL 353: - PowerPoint PPT Presentation

ENEL 353 F13 Section 02 Slides for Lecture 3 slide 2/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 3/22 Previous Lecture Todays Lecture Slides for Lecture 3 ENEL 353: Digital Circuits Fall 2013 Term a little more about


  1. ENEL 353 F13 Section 02 Slides for Lecture 3 slide 2/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 3/22 Previous Lecture Today’s Lecture Slides for Lecture 3 ENEL 353: Digital Circuits — Fall 2013 Term ◮ a little more about binary, octal, and hexadecimal numbers ◮ introduction to signed and unsigned number systems Steve Norman, PhD, PEng ◮ unsigned binary integer addition Number systems: decimal, binary, octal and hexadecimal. Electrical & Computer Engineering ◮ sign/magnitude representation of signed integers Schulich School of Engineering University of Calgary Related material in Harris & Harris (our course textbook): 13 September, 2013 ◮ Sections 1.4.4 and 1.4.5 ◮ the beginning of Section 1.4.6 slide 4/22 slide 5/22 slide 6/22 ENEL 353 F13 Section 02 Slides for Lecture 3 ENEL 353 F13 Section 02 Slides for Lecture 3 ENEL 353 F13 Section 02 Slides for Lecture 3 Repeat slide from previous lecture: Learn these Conversion between binary, octal, and hex Review of conversion between binary and hex and tables! conversion between binary and octal One more example: Convert 487 10 to hex and octal. (This problem was left unsolved in the previous lecture.) octal bit hex bit hex bit Hex to binary: Replace each hex digit with the equivalent 4-bit We can use repeated division to go from decimal to digit pattern digit pattern digit pattern binary pattern. hexadecimal . . . 0 000 0 0000 8 1000 Binary to hex, step 1: If necessary, add leading zeros so you division quotient remainder hex digit 1 001 1 0001 9 1001 can make groups of 4 bits. 487 / 16 30 7 7 2 010 2 0010 A 1010 30 / 16 1 14 E Binary to hex, step 2: Replace each group of 4 bits with the 3 011 3 0011 B 1011 1 / 16 0 1 1 equivalent hex digit. 4 100 4 0100 C 1100 5 101 5 0101 D 1101 Answer: 487 10 = 1E7 16 . For octal, see above, but use 3-bit groups instead of 4-bit 6 110 6 0110 E 1110 groups. To get the octal answer, we could start with 487 10 and do 7 111 7 0111 F 1111 repeated division again, this time dividing by 8. What would Why does this work? See the next slide . . . be a faster way to get the octal answer? ENEL 353 F13 Section 02 Slides for Lecture 3 slide 7/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 8/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 9/22 Detailed demonstration of conversion from binary Signed and unsigned number systems About the words signed and unsigned to hex: 1010 0110 1011 2 = A6B 16 From the previous slide: Signed and unsigned are adjectives 1 × 2 11 + 0 × 2 10 + 1 × 2 9 + 0 × 2 8 1010 0110 1011 2 = used to describe number systems . Signed and unsigned are adjectives used to describe number 0 × 2 7 + 1 × 2 6 + 1 × 2 5 + 0 × 2 4 + systems . They are also useful words for describing types in computer 1 × 2 3 + 0 × 2 2 + 1 × 2 1 + 1 × 2 0 + programming systems. A signed system has some negative numbers, zero, and some (1 × 2 3 + 0 × 2 2 + 1 × 2 1 + 0 × 2 0 ) × 2 8 = positive numbers. They are NOT fancy synonyms for “negative” and “positive”, (0 × 2 3 + 1 × 2 2 + 1 × 2 1 + 0 × 2 0 ) × 2 4 + and should NEVER used to describe individual values. An unsigned system has only zero and positive numbers. (1 × 2 3 + 0 × 2 2 + 1 × 2 1 + 1 × 2 0 ) × 2 0 + AVOID saying things like “ − 42 is signed” and “37 is unsigned”. Statements like that just don’t make sense! = 10 × 16 2 6 × 16 1 + + 11 × 16 0

  2. ENEL 353 F13 Section 02 Slides for Lecture 3 slide 10/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 11/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 12/22 Unsigned decimal addition Unsigned binary addition Doing one column of unsigned binary addition Addition in base two (or with any other radix) can be done Let’s add 268 10 and 437 10 , so we can quickly review an with essentially the same procedure as is used for decimal C in algorithm we learned as school kids: addition. A carries 1 1 + B Let’s demonstrate by adding two four-bit numbers: 2 6 8 0111 2 + 0110 2 . C out S + 4 3 7 To do the work, we use rules such as 7 0 5 Each column has three input bits: C in (carry in), A and B . ◮ 0 + 1 + 0 is 1 with a carry of 0, ◮ 0 + 1 + 1 is 0 with a carry of 1, Each column has two output bits: S (sum) and C out (carry Note that we have to use rules such as “8 + 7 is 5 with a carry out). of 1,” and “1 + 6 + 3 is 0 with a carry of 1.” ◮ and so on. slide 13/22 slide 14/22 slide 15/22 ENEL 353 F13 Section 02 Slides for Lecture 3 ENEL 353 F13 Section 02 Slides for Lecture 3 ENEL 353 F13 Section 02 Slides for Lecture 3 One column of unsigned binary addition: A table The full adder: Our first digital logic circuit! A four-bit unsigned binary adder of outputs generated by all possible combinations of input bits An electronic circuit can be built to match the truth table . . . A B C in Suppose we have lots of full adder circuits available, and we A B C in C out S Let’s replace all the ? Inputs and outputs are want to build a circuit to add the binary numbers A 3 A 2 A 1 A 0 0 0 0 ? ? symbols with correct bit communicated on wires . and B 3 B 2 B 1 B 0 . Let’s call the 4-bit sum S 3 S 2 S 1 S 0 . 0 0 1 ? ? values. full 0 1 0 ? ? For example, voltage near 0.0V could How many full adders do we need, and how should we wire This kind of table (without adder 0 1 1 ? ? indicate a bit value of 0, and voltage them together? any ? symbols) is usually 1 0 0 ? ? near 3.3V could indicate a bit value called a truth table . We’ll 1 0 1 ? ? of 1. read and write a lot of truth 1 1 0 ? ? C out S tables in ENEL 353. 1 1 1 ? ? ENEL 353 F13 Section 02 Slides for Lecture 3 slide 16/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 17/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 18/22 The width of a number system Overflow in fixed-width number systems A practical demonstration of overflow In C ++ , int and unsigned int types typically have a fixed width of 32 bits . . . In everyday work with decimal numbers we tend to use as #include <iostream> Addition (and other kinds of arithmetic) in a fixed-width many or as few digits as we need—we DON’T typically think using namespace std; number system can produce results that DON’T match the of numbers as having a fixed number of digits. int main() { “everyday math” result of the computation. // Note: u after all the digits indicates that But in digital circuits and computer systems, binary numbers // the type of a constant is unsigned. usually DO have a fixed number of bits, or width . For example, let’s add 1011 2 and 0110 2 with a 4-bit adder. unsigned int a = 4294967295u; Note that “everyday math” says 11 10 + 6 10 = 17 10 . In the previous example of binary addition, the numbers were unsigned int b = 2u; all 4 bits wide . cout << a << " + " << b << " is " << a + b << endl; return 0; } Output: 4294967295 + 2 = 1

  3. ENEL 353 F13 Section 02 Slides for Lecture 3 slide 19/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 20/22 ENEL 353 F13 Section 02 Slides for Lecture 3 slide 21/22 What happened in the 32-bit addition? Signed numbers Sign/magnitude numbers Note that 4294967295 10 = FFFFFFFF 16 . I deliberately picked Often digital hardware must be able to handle the possibility We use sign/magnitude in daily life with decimal numbers, a very big number for a to make this example work. of negative numbers . such as +5, − 37, 44. (If the sign is left out, we assume that How can we use sequences of 1’s and 0’s to represent numbers carry in: 1111 1111 1111 1111 1111 1111 1111 1100 it’s +.) that might be negative, might be zero, and might be positive? a : 1111 1111 1111 1111 1111 1111 1111 1111 For binary numbers, we can use 1 to stand for − and 0 to b : 0000 0000 0000 0000 0000 0000 0000 0010 The most obvious system is called sign/magnitude (sometimes stand for +. sum: 0000 0000 0000 0000 0000 0000 0000 0001 called “sign-and-magnitude”). Let’s look at some examples of binary sign/magnitude Another system, not so obvious, but used much more representation. The carry out from the leftmost column is not used—the sum often , is called two’s-complement . must be exactly 32 bits wide. slide 22/22 ENEL 353 F13 Section 02 Slides for Lecture 3 Next 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.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend