Data Representation
Lecture 1
    How data are represented in Computer?
• In order to be understood by a computer, data and programs
  need to be represented appropriately
• Coding systems: Used to represent data and programs in a
  manner understood by the computer
• Computers are made of a series of switches
• Each switch has two states: ON or OFF
• Each state can be represented by a number 1 for “ON” and 0 for
  “OFF”
           Digital Data Representation
 Bit: The smallest unit of data that a binary computer can recognize (a
  single 1 or 0)
 Byte = 8 bits
 Byte terminology used to express the size of documents and other files,
  programs, etc.
                     Digital Data Representation
• Prefixes are often used to express larger quantities of bytes: kilobyte
  (KB), megabyte (MB), gigabyte (GB), terabyte (TB), petabyte (PB),
  exabyte (EB), zettabyte (ZB), yottabyte (YB).
1 Kilobytes (KB)   210 bytes 1024 bytes
1 Megabytes        220 bytes 1024 KB
(MG)
1 Gegabytes        230 bytes 1024 MB
(GB)
1 Terabytes (TB) 240 bytes 1024 GB
             Data vs. Information
• Data
   – Raw, unorganized facts
   – Can be in the form of text,
     graphics, audio, or video
• Information
   – Data that has been processed
     into a meaningful form
• Information processing
   – Converting data into
     information
                         Representing Text
• Each character (letter, punctuation, etc.) is assigned a unique bit
  pattern.
• ASCII (American Standard Code for Information Interchange) coding
  system traditionally used with personal computers
•   Standard ASCII: Uses patterns of 7-bits to represent most symbols used in written
    English text
     – Extended ASCII: ISO developed a number of 8 bit extensions to ASCII, each
       designed to accommodate a major language group
     – Unicode: newer code (32 bits per character is common); universal coding
       standard designed to represent text-based data written in any ancient or modern
       language
    Representing Numeric Values
• Numbering System: A way of representing numbers.
• The position of the digits determines the power to which
  the base number is raised.
• Binary notation: Uses bits to represent a number in base
  two.
                      Numbering system
          Binary                         Decimal
          Bi -> 2                        Dec -> 10
          base2                           base10
                       Decimal Numbers
•   Base=10
•   Represented using 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
•   We use a positional notation system.
•   Weight= BasePos
     Position     Pos 8    Pos 7   Pos 6   Pos 5 Pos 4   Pos 3   Pos 2   Pos 1   Pos 0
     Weight        108      107     106     105   104     103     102     101     100
      Value     10000000 10000000 1000000 100000 10000   1000     100     10       1
                             Binary Numbers
 • Base=2
 • Represented using 2 digits: 0, 1
Position   Pos 8   Pos 7   Pos 6   Pos 5   Pos 4 Pos 3 Pos 2 Pos 1 Pos 0   .   Pos -1   Pos -2
Weight      28      27      26      25      24    23    22    21    20     .    2-1      2-2
 Value     256     128      64      32      16    8     4      2     1     .    0.5     0.25
Converting Base-2 to Base-10
             (1 0                   0        1 1)
                                                       2
                         OFF
                                   OFF
                ON
                                             ON
                                                      ON
 Exponent:
 Calculation:16 0 0 2 1
                     +         +         +        +        =
                 (19)10
       Decimal to Binary Conversion
                           Method I:
                    Use repeated subtraction.
        Subtract largest power of 2, then next largest, etc.
Powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2n
Exponent:    0, 1, 2, 3, 4, 5, 6,      7, 8, 9, 10 , n
            20 21 2 2 23 24 25 26        27    28    29 210 2n
                                                                 11
   Decimal to Binary Conversion
• Suppose x = 156410
                                  12
                 Decimal to Binary Conversion
                   Suppose x = 156410
Subtract 1024:   1564-1024 (210) = 540  n=10 or 1 in the (210)’s position
Subtract 512:    540-512 (29) = 28      n=9 or 1 in the (29)’s position
28=256, 27=128, 26=64, 25=32 > 28, so we have 0 in all of these positions
Subtract 16:      28-16 (24) = 12       n=4 or 1 in (24)’s position
Subtract 8:       12 – 8 (23) = 4       n=3 or 1 in (23)’s position
Subtract 4:       4 – 4 (22) = 0        n=2 or 1 in (22)’s position
                        Thus:
         156410 = (1 1 0 0 0 0 1 1 1 0 0)2
                                                                             13
  Decimal to Binary Conversion
                Method II:
       Use repeated division by radix.
2 | 1564                     2|__24_
    782
 2|_____       R=0              12
                             2|_____     R=0
                                                 
  2|_____
     391       R=0               6
                                2|_____  R=0
     195
   2|_____    R=1                   3
                                  2|_____ R= 0
      97
     2|_____   R=1                    1
                                   2|_____R=1
      2|_____
         48     R=1                    0   R=1
          24    R=0
     Collect remainders in reverse order
             11000011100
                                                 14
                        Representing Graphics
• Graphics (still images
  such as photos or
  drawings)
   – Bitmapped images: A variety of bit
     depths are possible (4, 8, 24 bits)
       • More bits = more colors
   – Graphics Interchange Format (GIF):
     GIFs store at most 8 bits per pixel,
     so they are limited to 256 colors.
   – Joint Photographic Experts Group
     (JPEG): Color JPEG images store 24
     bits per pixel.
   – Portable Network Graphics (PNG):
     GIF files can use only 1, 2, 4, or 8
     bits per pixel.
        Representing Audio and Video Data
• Audio data: Must be in digital form in order to be stored on or
  processed by a computer
    – Often compressed when sent over the Internet
        • MP3 files
• Video data: Displayed using a collection of frames, each frame contains
  a still image
    – Amount of data can be substantial, but can be compressed
    – Developers keep on defining new formats aiming for more quality
      with less space.
                                                                    16