Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2 Number Representation, Overflow and Logic Topics Adders Math Behind Excess-3 Overflow Unsigned, signed-magnitude Two’s Complement Gray Code Boolean.

Similar presentations


Presentation on theme: "Lecture 2 Number Representation, Overflow and Logic Topics Adders Math Behind Excess-3 Overflow Unsigned, signed-magnitude Two’s Complement Gray Code Boolean."— Presentation transcript:

1 Lecture 2 Number Representation, Overflow and Logic Topics Adders Math Behind Excess-3 Overflow Unsigned, signed-magnitude Two’s Complement Gray Code Boolean Logic August 26, 2015 CSCE 211 Digital Design

2 – 2 – CSCE 211H Fall 2015 Last Time:! Base R  Base 10 conversions Base R  Base 10 Base 10  Base R Base 10 fractions  Base R fractions Ripple carry adder Signed Magnitude Two’s complementNew: Things from last Lecture: Slides 20-31 Two’s Complement arithmetic Basic Gates: AND, OR, NOT, XOR, NOR, NAND Adders Binary Coded Decimal Two’s Complement Overflow Gray Code Boolean LogicHomework 1) Two’s complement of 87, and 2) Two’s complement of -43, 3) 2.26 (sign extension), and 4) 2.29, Email: mm @ sc.edu

3 – 3 – CSCE 211H Fall 2015

4 – 4 – CSCE 211H Fall 2015

5 – 5 – CSCE 211H Fall 2015

6 – 6 – CSCE 211H Fall 2015 Octal Arithmetic 17768432 17768432 +1432 - 1776

7 – 7 – CSCE 211H Fall 2015 Ripple Carry Adder

8 – 8 – CSCE 211H Fall 2015 Excess n code Excess-3 code Excess-127 code for IEEE 754 floating point

9 – 9 – CSCE 211H Fall 2015 Excess-3 Code for Decimals Justification ex3[7] = 1010 // excess-3 representation ex3[7] = 1010 // excess-3 representation +ex3[4] = 0111 +ex3[4] = 0111 10001// carry=1, sum=0001 not correct ex3 // it should be 0100 which is 0001+0011 So if there is a carry then we should correct the sum by adding 3. The math behind this is If x + y >= 10 then ex3[x] +ex3[y] = bcd[x] + 3 + bcd[y] + 3 But since x+y =bcd[x] + bcd[y] >= 10 we have ex3[x] +ex3[y] = bcd[x]+bcd[y] + 6 >= 10 + 6 = 16 So the carry is correct but the sum digit = (ex3[x] +ex3[y]) mod 16 = (bcd[x]+bcd[y] +6) - 16 So the sum digit is the correct bcd of (x+y) but not excess-3 so we need to add 3.

10 – 10 – CSCE 211H Fall 2015 Excess-3 Code for Decimals Justification ex3[2] = 0101 // excess-3 representation ex3[2] = 0101 // excess-3 representation +ex3[6] = 1001 +ex3[6] = 1001 1110 1110 So if there is no carry then we should correct the sum by... And the math in this case: If x + y < 10 then ex3[x] + ex3[y] =

11 – 11 – CSCE 211H Fall 2015 Why Excess-3 Code for Decimals ?

12 – 12 – CSCE 211H Fall 2015 IEEE 754 floating pt – Excess 127 IEEE 754 single-precision binary floating-point format: binary32 The IEEE 754 standard specifies a binary32 as having: Sign bitSign bit: 1 bit Sign bit ExponentExponent width: 8 bits Exponent SignificandSignificand precision: 24 bits (23 explicitly stored) precision Significandprecision http://en.wikipedia.org/wiki/Single_precision

13 – 13 – CSCE 211H Fall 2015 One more example 0 11110000 10101 0000 …000 http://en.wikipedia.org/wiki/Single_precision

14 – 14 – CSCE 211H Fall 2015 Special Exponents Expfield = e  expField = 1111 1111 expField = 0000 0000

15 – 15 – CSCE 211H Fall 2015 Floating point demographics How many 32 bit IEEE754 floats are there? Easier question first how many positive floats with expField = 1000 0000?

16 – 16 – CSCE 211H Fall 2015 Floating point operations AdditionMultiplication

17 – 17 – CSCE 211H Fall 2015 What is overflow? In general what does overflow mean? For unsigned integers? Examples For signed magnitude or two’s complement what does overflow mean? For floats? Underflow?

18 – 18 – CSCE 211H Fall 2015 Overflow in Two’s Complement x n x n-1 x n-2 …x 2 x 1 x 0 +y n y n-1 y n-2 …y 2 y 1 y 0 s n+1 s n s n-1 s n-2 …s 2 s 1 s 0 Overflow Case 1 positive + positive = negative !? Meaning of course that the sign bits of both addends is 0 and the sign bit of the sum is 1 Case 2 …

19 – 19 – CSCE 211H Fall 2015 Gray Code In some mechanical devices you want to encode positions as binary strings in such a way that positions close to each other are represented by strings that are close together. Gray code – adjacent positions differ in only one bit 000 001 011 010 110 111 101 100 Figure 2-6 encoding disk

20 – 20 – CSCE 211H Fall 2015 Construction of Gray Codes Gray Codes are reflective Algorithm for construction of Gray Codes on n-bits  A 1-bit Gray code has two words 0 and 1.  The first 2n words of an (n+1)-bit gray code are the words of the n-bit gray code with a leading 0 added.  The next 2n words of an (n+1)-bit gray code are the words of the n-bit gray code but written in reverse order with a leading 1 added.

21 – 21 – CSCE 211H Fall 2015 Construction of Gray Codes 1-bit gray code 0 1 2-bit gray code 00 01 11 10 3-bit gray code 0 00 0 01 0 11 0 10 1 10 1 11 1 01 1 00 4-bit gray code 0 000

22 – 22 – CSCE 211H Fall 2015 Representations of Characters How many characters do we need to represent? How many bits does this take ? ASCIIUNICODE

23 – 23 – CSCE 211H Fall 2015 Codes representing characters ASCII - American Standard Code for Information Interchange 8 bits = 7 + parity ASCII table in chapter 2, (Table 2-11) 32 Control characters + 96 printable characters Unicode 16 bits http://en.wikipedia.org/wiki/ASCII

24 – 24 – CSCE 211H Fall 2015 N-cubes 1-cube2-cube3-cube Traversing in gray-code order

25 – 25 – CSCE 211H Fall 2015 Parity Bits Even parity bit – parity bit is set so that the number of ones is even Odd parity bit

26 – 26 – CSCE 211H Fall 2015 Error Correcting codes For an n-bit code, consider the hypercube of dimension n Choose some subset of the nodes as code words. Suppose the distance between any two two code words is at least 3. Now consider transmission errors. Then if there is an error in transmitting just one bit then the distance from the received word to one code word is one, distances to other code words are at least two. Single error correcting, double error detecting. Such codes are called Hamming codes after their inventor Richard Hamming.

27 – 27 – CSCE 211H Fall 2015 Boolean Algebra George Boole (1854) invented a two valued algebra To “give expression … to the fundamental laws of reasoning in the symbolic language of a Calculus.” 1938 Claude Shannon at Bell Labs noted that this Boolean logic could be used to describe switching circuits. (Switching Algebra) In Shannon’s view a relay has two positions open and closed representing 1 and 0. Collections of relays satisfied the properties of Boolean algebra.

28 – 28 – CSCE 211H Fall 2015 Homework Set 2 1.What is the representation of the maximum unsigned integer using 12 bits? a) Representation (string of 12 bits) (b) value in decimal 2.What is the representation of the maximum two’s complement integer using 12 bits? a) Representation (string of 12 bits) (b) value in decimal b) What is the representation of -37 in two’s complement using 12 bits? c) Representation (string of 12 bits) (b) value in decimal 3.IEEE-754 32 bit float a) What is the representation and value of the largest (non infinite) float? b) What is the representation of 212.375 as a IEEE 754 float? c) How many floats are there >= 16 ? d) Are there more positive floats > 16 or < 16?


Download ppt "Lecture 2 Number Representation, Overflow and Logic Topics Adders Math Behind Excess-3 Overflow Unsigned, signed-magnitude Two’s Complement Gray Code Boolean."

Similar presentations


Ads by Google