1 / 28

Lecture 2 Number Representation, Overflow and Logic

Lecture 2 Number Representation, Overflow and Logic. CSCE 211 Digital Design. Topics Adders Math Behind Excess-3 Overflow Unsigned, signed-magnitude Two’s Complement Gray Code Boolean Logic. August 26, 2015. Last Time:! Base R  Base 10 conversions Base R  Base 10

asnyder
Download Presentation

Lecture 2 Number Representation, Overflow and Logic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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 complement • New: • 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 Logic • Homework • 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. Octal Arithmetic • 1776 8432 • + 1432 - 1776

  4. Ripple Carry Adder

  5. Excess n code • Excess-3 code • Excess-127 code for IEEE 754 floating point

  6. Excess-3 Code for Decimals Justification • ex3[7] = 1010 // excess-3 representation • + 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.

  7. Excess-3 Code for Decimals Justification • ex3[2] = 0101 // excess-3 representation • + ex3[6] = 1001 • 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] =

  8. Why Excess-3 Code for Decimals ?

  9. 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 bit: 1 bit • Exponent width: 8 bits • Significandprecision: 24 bits (23 explicitly stored) http://en.wikipedia.org/wiki/Single_precision

  10. One more example • 0 11110000 10101 0000 …000 http://en.wikipedia.org/wiki/Single_precision

  11. Special Exponents • Expfield = e  expField = 1111 1111 • expField = 0000 0000

  12. Floating point demographics • How many 32 bit IEEE754 floats are there? • Easier question first how many positive floats with expField = 1000 0000?

  13. Floating point operations • Addition • Multiplication

  14. 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?

  15. Overflow in Two’s Complement • xn xn-1 xn-2 … x2 x1 x0 • + yn yn-1 yn-2 … y2 y1 y0 • sn+1sn sn-1 sn-2 … s2 s1 s0 • 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 …

  16. 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

  17. 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.

  18. Construction of Gray Codes 4-bit gray code • 0 000 • 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

  19. Representations of Characters • How many characters do we need to represent? • How many bits does this take ? • ASCII • UNICODE

  20. 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

  21. N-cubes • 1-cube • 2-cube • 3-cube • Traversing in gray-code order

  22. Parity Bits • Even parity bit – parity bit is set so that the number of ones is even • Odd parity bit

  23. 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.

  24. 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.

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

More Related