Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lec 02 data representation part 2

1,057 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Lec 02 data representation part 2

  1. 1. Data Representation COAL Computer Organization and Assembly Language
  2. 2. Outline <ul><li>Floating Point Numbers Representation </li></ul><ul><li>Carry and Overflow </li></ul><ul><li>Character Storage </li></ul>
  3. 3. Floating-Point Representation <ul><li>The signed magnitude, one’s complement, and two’s complement representation that we have just presented deal with integer values only. </li></ul><ul><li>Without modification, these formats are not useful in scientific or business applications that deal with real number values. </li></ul><ul><li>Floating-point representation solves this problem. </li></ul>
  4. 4. Floating-Point Representation <ul><li>If we are clever programmers, we can perform floating-point calculations using any integer format. </li></ul><ul><li>This is called floating-point emulation , because floating point values aren’t stored as such, we just create programs that make it seem as if floating-point values are being used. </li></ul><ul><li>Most of today’s computers are equipped with specialized hardware that performs floating-point arithmetic with no special programming required. </li></ul>
  5. 5. Floating-Point Representation <ul><li>Floating-point numbers allow an arbitrary number of decimal places to the right of the decimal point. </li></ul><ul><ul><li>For example: 0.5  0.25 = 0.125 </li></ul></ul><ul><li>They are often expressed in scientific notation. </li></ul><ul><ul><li>For example: </li></ul></ul><ul><ul><ul><li>0.125 = 1.25  10 -1 </li></ul></ul></ul><ul><ul><ul><li>5,000,000 = 5.0  10 6 </li></ul></ul></ul>
  6. 6. Floating-Point Representation <ul><li>Computers use a form of scientific notation for floating-point representation </li></ul><ul><li>Numbers written in scientific notation have three components: </li></ul>
  7. 7. <ul><li>Computer representation of a floating-point number consists of three fixed-size fields: </li></ul><ul><li>This is the standard arrangement of these fields. </li></ul>Floating-Point Representation
  8. 8. <ul><li>The one-bit sign field is the sign of the stored value. </li></ul><ul><li>The size of the exponent field, determines the range of values that can be represented. </li></ul><ul><li>The size of the significand determines the precision of the representation. </li></ul>Floating-Point Representation
  9. 9. <ul><li>The IEEE-754 single precision floating point standard uses an 8-bit exponent and a 23-bit significand. </li></ul><ul><li>The IEEE-754 double precision standard uses an 11-bit exponent and a 52-bit significand. </li></ul>Floating-Point Representation For illustrative purposes, we will use a 14-bit model with a 5-bit exponent and an 8-bit significand.
  10. 10. <ul><li>The significand of a floating-point number is always preceded by an implied binary point. </li></ul><ul><li>Thus, the significand always contains a fractional binary value. </li></ul><ul><li>The exponent indicates the power of 2 to which the significand is raised. </li></ul>Floating-Point Representation
  11. 11. <ul><li>Example: </li></ul><ul><ul><li>Express 32 10 in the simplified 14-bit floating-point model. </li></ul></ul><ul><li>We know that 32 is 2 5 . So in (binary) scientific notation 32 = 1.0 x 2 5 = 0.1 x 2 6 . </li></ul><ul><li>Using this information, we put 110 (= 6 10 ) in the exponent field and 1 in the significand as shown. </li></ul>Floating-Point Representation
  12. 12. <ul><li>The illustrations shown at the right are all equivalent representations for 32 using our simplified model. </li></ul><ul><li>Not only do these synonymous representations waste space, but they can also cause confusion. </li></ul>2.5 Floating-Point Representation
  13. 13. <ul><li>Another problem with our system is that we have made no allowances for negative exponents. We have no way to express 0.5 (=2 -1 )! (Notice that there is no sign in the exponent field!) </li></ul>Floating-Point Representation All of these problems can be fixed with no changes to our basic model.
  14. 14. <ul><li>To resolve the problem of synonymous forms, we will establish a rule that the first digit of the significand must be 1. This results in a unique pattern for each floating-point number. </li></ul><ul><ul><li>In the IEEE-754 standard, this 1 is implied meaning that a 1 is assumed after the binary point. </li></ul></ul><ul><ul><li>By using an implied 1, we increase the precision of the representation by a power of two. (Why?) </li></ul></ul>2.5 Floating-Point Representation In our simple instructional model, we will use no implied bits.
  15. 15. <ul><li>To provide for negative exponents, we will use a biased exponent . </li></ul><ul><li>A bias is a number that is approximately midway in the range of values expressible by the exponent. We subtract the bias from the value in the exponent to determine its true value. </li></ul><ul><ul><li>In our case, we have a 5-bit exponent. We will use 16 for our bias. This is called excess-16 representation. </li></ul></ul><ul><li>In our model, exponent values less than 16 are negative, representing fractional numbers. </li></ul>2.5 Floating-Point Representation
  16. 16. <ul><li>Example: </li></ul><ul><ul><li>Express 32 10 in the revised 14-bit floating-point model. </li></ul></ul><ul><li>We know that 32 = 1.0 x 2 5 = 0.1 x 2 6 . </li></ul><ul><li>To use our excess 16 biased exponent, we add 16 to 6, giving 22 10 (=10110 2 ). </li></ul><ul><li>Graphically: </li></ul>Floating-Point Representation
  17. 17. <ul><li>Example: </li></ul><ul><ul><li>Express 0.0625 10 in the revised 14-bit floating-point model. </li></ul></ul><ul><li>We know that 0.0625 is 2 -4 . So in (binary) scientific notation 0.0625 = 1.0 x 2 -4 = 0.1 x 2 -3 . </li></ul><ul><li>To use our excess 16 biased exponent, we add 16 to -3, giving 13 10 (=01101 2 ). </li></ul>Floating-Point Representation
  18. 18. <ul><li>Example: </li></ul><ul><ul><li>Express -26.625 10 in the revised 14-bit floating-point model. </li></ul></ul><ul><li>We find 26.625 10 = 11010.101 2 . Normalizing, we have: 26.625 10 = 0.11010101 x 2 5 . </li></ul><ul><li>To use our excess 16 biased exponent, we add 16 to 5, giving 21 10 (=10101 2 ). We also need a 1 in the sign bit. </li></ul>Floating-Point Representation
  19. 19. <ul><li>The IEEE-754 single precision floating point standard uses bias of 127 over its 8-bit exponent. </li></ul><ul><ul><li>An exponent of 255 indicates a special value. </li></ul></ul><ul><ul><ul><li>If the significand is zero, the value is  infinity. </li></ul></ul></ul><ul><ul><ul><li>If the significand is nonzero, the value is NaN, “not a number,” often used to flag an error condition. </li></ul></ul></ul><ul><li>The double precision standard has a bias of 1023 over its 11-bit exponent. </li></ul><ul><ul><li>The “special” exponent value for a double precision number is 2047, instead of the 255 used by the single precision standard. </li></ul></ul>Floating-Point Representation
  20. 20. <ul><li>Both the 14-bit model that we have presented and the IEEE-754 floating point standard allow two representations for zero. </li></ul><ul><ul><li>Zero is indicated by all zeros in the exponent and the significand, but the sign bit can be either 0 or 1. </li></ul></ul><ul><li>This is why programmers should avoid testing a floating-point value for equality to zero. </li></ul><ul><ul><li>Negative zero does not equal positive zero. </li></ul></ul>Floating-Point Representation
  21. 21. <ul><li>Floating-point addition and subtraction are done using methods analogous to how we perform calculations using pencil and paper. </li></ul><ul><li>The first thing that we do is express both operands in the same exponential power, then add the numbers, preserving the exponent in the sum. </li></ul><ul><li>If the exponent requires adjustment, we do so at the end of the calculation. </li></ul>Floating-Point Representation
  22. 22. <ul><li>Example: </li></ul><ul><ul><li>Find the sum of 12 10 and 1.25 10 using the 14-bit floating-point model. </li></ul></ul><ul><li>We find 12 10 = 0.1100 x 2 4 . And 1.25 10 = 0.101 x 2 1 = 0.000101 x 2 4 . </li></ul>Floating-Point Representation <ul><li>Thus, our sum is 0.110101 x 2 4. </li></ul>
  23. 23. <ul><li>Floating-point multiplication is also carried out in a manner akin to how we perform multiplication using pencil and paper. </li></ul><ul><li>We multiply the two operands and add their exponents. </li></ul><ul><li>If the exponent requires adjustment, we do so at the end of the calculation. </li></ul>Floating-Point Representation
  24. 24. <ul><li>Example: </li></ul><ul><ul><li>Find the product of 12 10 and 1.25 10 using the 14-bit floating-point model. </li></ul></ul><ul><li>We find 12 10 = 0.1100 x 2 4 . And 1.25 10 = 0.101 x 2 1 . </li></ul>Floating-Point Representation <ul><li>Thus, our product is 0.0111100 x 2 5 = 0.1111 x 2 4. </li></ul><ul><li>The normalized product requires an exponent of 20 10 = 10110 2 . </li></ul>
  25. 25. <ul><li>No matter how many bits we use in a floating-point representation, our model must be finite. </li></ul><ul><li>The real number system is, of course, infinite, so our models can give nothing more than an approximation of a real value. </li></ul><ul><li>At some point, every model breaks down, introducing errors into our calculations. </li></ul><ul><li>By using a greater number of bits in our model, we can reduce these errors, but we can never totally eliminate them. </li></ul>Floating-Point Representation
  26. 26. <ul><li>Our job becomes one of reducing error, or at least being aware of the possible magnitude of error in our calculations. </li></ul><ul><li>We must also be aware that errors can compound through repetitive arithmetic operations. </li></ul><ul><li>For example, our 14-bit model cannot exactly represent the decimal value 128.5. In binary, it is 9 bits wide: </li></ul><ul><ul><li>10000000.1 2 = 128.5 10 </li></ul></ul>Floating-Point Representation
  27. 27. Character Storage <ul><li>Character sets </li></ul><ul><ul><li>Standard ASCII: 7-bit character codes (0 – 127) </li></ul></ul><ul><ul><li>Extended ASCII: 8-bit character codes (0 – 255) </li></ul></ul><ul><ul><li>Unicode: 16-bit character codes (0 – 65,535) </li></ul></ul><ul><ul><li>Unicode standard represents a universal character set </li></ul></ul><ul><ul><ul><li>Defines codes for characters used in all major languages </li></ul></ul></ul><ul><ul><ul><li>Used in Windows-XP: each character is encoded as 16 bits </li></ul></ul></ul><ul><ul><li>UTF-8: variable-length encoding used in HTML </li></ul></ul><ul><ul><ul><li>Encodes all Unicode characters </li></ul></ul></ul><ul><ul><ul><li>Uses 1 byte for ASCII, but multiple bytes for other characters </li></ul></ul></ul><ul><li>Null-terminated String </li></ul><ul><ul><li>Array of characters followed by a NULL character </li></ul></ul>
  28. 28. ASCII Codes <ul><li>Examples: </li></ul><ul><ul><li>ASCII code for space character = 20 (hex) = 32 (decimal) </li></ul></ul><ul><ul><li>ASCII code for ‘A' = 41 (hex) = 65 (decimal) </li></ul></ul><ul><ul><li>ASCII code for 'a' = 61 (hex) = 97 (decimal) </li></ul></ul>
  29. 29. Control Characters <ul><li>The first 32 characters of ASCII table are used for control </li></ul><ul><li>Control character codes = 00 to 1F (hex) </li></ul><ul><li>Examples of Control Characters </li></ul><ul><ul><li>Character 0 is the NULL character  used to terminate a string </li></ul></ul><ul><ul><li>Character 9 is the Horizontal Tab (HT) character </li></ul></ul><ul><ul><li>Character 0A (hex) = 10 (decimal) is the Line Feed (LF) </li></ul></ul><ul><ul><li>Character 0D (hex) = 13 (decimal) is the Carriage Return (CR) </li></ul></ul><ul><ul><li>The LF and CR characters are used together </li></ul></ul><ul><ul><ul><li>They advance the cursor to the beginning of next line </li></ul></ul></ul><ul><li>One control character appears at end of ASCII table </li></ul><ul><ul><li>Character 7F (hex) is the Delete (DEL) character </li></ul></ul>
  30. 30. ASCII Groups <ul><li>4 groups of 32 characters </li></ul><ul><li>G1  Codes 0-1F (31) [Non printing Control characters] </li></ul><ul><li>G2  Codes 30-39H [0---9] + punctuation symbols etc </li></ul><ul><ul><li>Numeric digits differs in H.O Nibble from their numeric values </li></ul></ul><ul><ul><li>Subtract 30 to get numeric value </li></ul></ul><ul><li>G3  Codes 41-5A (65-90) [A---Z + 6 codes fro special symbols] </li></ul><ul><li>G4  Codes 61-7A [a—z] +special symbols </li></ul><ul><ul><li>Upper and Lower differs in bit number 5 </li></ul></ul>
  31. 31. ASCII Groups <ul><li>Bits 5 and 6 determines the groups as shown in table below </li></ul>
  32. 32. Parity Bit <ul><li>Data errors can occur during data transmission or storage/retrieval. </li></ul><ul><li>The 8th bit in the ASCII code is used for error checking. </li></ul><ul><li>This bit is usually referred to as the parity bit . </li></ul><ul><li>There are two ways for error checking: </li></ul><ul><ul><li>Even Parity : Where the 8th bit is set such that the total number of 1s in the 8-bit code word is even. </li></ul></ul><ul><ul><li>Odd Parity : The 8th bit is set such that the total number of 1s in the 8-bit code word is odd. </li></ul></ul>
  33. 33. Boolean Operations <ul><li>NOT </li></ul><ul><li>AND </li></ul><ul><li>OR </li></ul><ul><li>Operator Precedence </li></ul><ul><li>Truth Tables </li></ul>
  34. 34. Boolean Algebra <ul><li>Based on symbolic logic , designed by George Boole </li></ul><ul><li>Boolean expressions created from: </li></ul><ul><ul><li>NOT, AND, OR </li></ul></ul>
  35. 35. NOT <ul><li>Inverts (reverses) a boolean value </li></ul><ul><li>Truth table for Boolean NOT operator: </li></ul>Digital gate diagram for NOT:
  36. 36. AND <ul><li>Truth table for Boolean AND operator: </li></ul><ul><li>Forcing ZERO/FALSE result (AND with ZERO) </li></ul><ul><li>If NO CHANGE required, AND with ONE </li></ul>Digital gate diagram for AND:
  37. 37. OR <ul><li>Truth table for Boolean OR operator: </li></ul><ul><li>Forcing ONE (OR with ONE) </li></ul><ul><li>NO CHANGE (OR with ZERO) </li></ul>Digital gate diagram for OR:
  38. 38. XOR <ul><li>If both operands EQUAL, the result is ZERO else ONE </li></ul><ul><li>Closer to English meaning or the word ‘OR’ </li></ul><ul><li>INVERSING OPERAND (XOR with ONE) </li></ul><ul><li>NO CHANGE (XOR with ZERO) </li></ul>
  39. 39. Operator Precedence <ul><li>Examples showing the order of operations: </li></ul>
  40. 40. Truth Tables (1 of 3) <ul><li>A Boolean function has one or more Boolean inputs, and returns a single Boolean output. </li></ul><ul><li>A truth table shows all the inputs and outputs of a Boolean function </li></ul>Example:  X  Y
  41. 41. Truth Tables (2 of 3) <ul><li>Example: X   Y </li></ul>

×