1 / 13

COE 205

COE 205. Lecture 5: Data Representation. Data in Computers. Computers understand binary numbers only: Numbers: Represented in binary Integers: +33, -37, +267 Reals: -123.45 E16, -59.6 E-12 Characters: Alphanumeric: A, c, Ctrl, Shift Represented by numeric codes Multimedia

tosca
Download Presentation

COE 205

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. COE 205 Lecture 5: Data Representation COE 205

  2. Data in Computers • Computers understand binary numbers only: • Numbers: • Represented in binary • Integers: +33, -37, +267 • Reals: -123.45 E16, -59.6 E-12 • Characters: Alphanumeric: A, c, Ctrl, Shift • Represented by numeric codes • Multimedia • Still Images: Many formats, all numeric. Based on numeric representation of the RGB components of each point of the image (pixel) • Video Images: Many formats also. Based on same principal as still images but applied on moving portions of the image only. • Sounds: Many formats. All numeric. Based on numeric representation of the amplitude of the sound wave over time. • Records and Database Elements: • Combination of Alphanumeric strings and numbers • Scientific Data • Combination of Numbers, Records, Multimedia and Statistical Data (numbers) COE 205

  3. What need to be represented • Numbers • Characters • No need to represent other items • No need to represent Images at CPU level • No need to represent Sounds at CPU level • No need to represent records at CPU level • Taken care by HL language constructs • Goal: Machine independent representation: STANDARD From CPU point of view: ONLY Binary To Standardize: At CPU Level Need to represent: Represent ONLY Numbers and Characters COE 205

  4. Numbering Systems N = dw-1Bw-1 +…+ diBi + d1B1 +d0B0 di: digits; B: Base di in [0, B-1] (728)10 = (1011011000)2= (1330)8 = (2D8)16 728d = 1011011000b = 1330o = 2D8h COE 205

  5. Number ConversionBinary - Hexadecimal 0 00 Binary to Hexadecimal 000100110100110101101100 Binary to Octal 001110101101100 Conv. Table Lookup Conversion Table Lookup 134D6C 16554 Hexadecimal to Binary 5D1F8 Octal to Binary 5361 Conv. Table Lookup Conversion Table Lookup 101 011 110 001 0101 1101 0001 1111 1000 Hex  Octal: Go to Binary First COE 205

  6. Number ConversionDecimal – Binary, Octal, Hex • Binary, Octal, Hex  Decimal: • Represent the number in base 10 and compute the operations: • 110110b = 1x25 + 1x24 + 0x23 + 1x22 + 1x21 + 0x20 = 54 • 236o = 2x82 + 3x81 + 6x80 = 158 • 3Ch = 3x161 + Cx160 = 60 • Decimal  Binary, Octal, Hex • Remainder Set of Successive Division by Target Base (2, 8 or 16) N = Q0 x 2 + R0First Division Q0 = Q1 x 2 + R1Second Division Q1 = Q2 x 2 + R2Third Division …. Qn-1 = 0 x 2 + RnCannot divide anymore N = (((((…(Rn x2) x 2 + Rn-1) x 2 + .) x2 + …..x2 + R1) x2 + R0 N = Rn x 2n + Rn-1 x 2n-1 + ….. + R1 x 2 + R0 COE 205

  7. ACSII or Decimal vs Binary Numbers • Attractive because: Human- Friendly representation • Non attractive to computers: • Understand only binary • Binary operations easy to perform • Does not know how to perform operations on ASCII or Decimal number. • Need to convert ASCII/Decimal to binary before and after operation • Used only for I/O (User Interface) Use Binary Representation For Internal Computations Convert to/from ASCII for I/O Only COE 205

  8. Number Representation • Numbers in computers • Just a representation of real numbers • Real numbers have an infinite number of digits 153ten = …..00000…0000010011001two = 0000 0000 1001 1001two in a 16 bits word Add, Subtract, Multiply, Divide Result bigger than number of available slots (bits) Overflow COE 205

  9. Signed Numbers • Subtraction of a big number from small number is a negative number Need for Signed Numbers Representation • Three Main ways: • Sign + Magnitude • 1’s Complement • 2’s Complement COE 205

  10. Sign and Magnitude Intuitive Representation: Sign + Magnitude Sign Magnitude • Range [-2n-1 -1 , +2n-1-1] • 8 bits: [-127, +127] • 12 bits: [-2047, +2047] • Advantages: Straight Forward • Disadvantages • Has the problem of double representing the 0 (–0 and +0), • Complicates the design of the logic circuits that handle signed-numbers arithmetic COE 205

  11. One’s Complement • Negative numbers are bit-to-bit complements of positive numbers • +9 on 8 bits = 00001001 • -9 on 8 bits = 11110110 • Range [-2n-1 -1 , +2n-1-1] • 8 bits: [-127, +127] • 12 bits: [-2047, +2047] • Advantages • Easy Representation • Easier arithmetic operations (add/sub) than sign + magnitude • Disadvantages • Has the problem of double representing the 0 (–0 and +0), • Add/Sub still relatively complex Examples: 0111 + 0111 0001 – 0111 0111 – 0001 COE 205

  12. Two’s Complement • Negative number represented as bit to bit complement of positive number plus 1 • Coming from: x + (-x) = 0 • Given x + x = -1 (check for any number) • Range [-2n-1, +2n-1-1] • 8 bits: [-128, +127] • 12 bits: [-2048, +2047] • Advantages • No double representation of 0 (the 2's complement of 0 is still 0), • Simplest Add/Subtract circuit design, • Add/Subtract operations is done in one-step, • The end result is already represented in 2's complement (not when overflow). COE 205

  13. Character Representation • ASCII • Broadly Used • Standard • Limited in representing other languages • 7 bits + 1 bit (parity) • Even Parity: put 1 in PB if # of 1s is even • Odd Parity: put 1 in PB if # of 1s is odd • Unicode • 16 bits • Used to represent chars of all languages COE 205

More Related