# Lecture 2 Introduction to Data Representation

Document Sample

```					                                                                                                  What do we mean by data?
n   Many definitions are possible depending on context

Lecture 2: Introduction to Data                                                      u   We will say that:
Representation                                                                    n   data is a physical representation of information
u   Data can be stored
n   e.g.: computer disk, cash till
Digital Electronics I
u   Data can be transmitted
n   e.g.: fax
u   Data can be processed
n   e.g.: cash till

PAN/PYKC 8/10/02      Dept of EEE, Imperial College   Digital Electronics I. Slide 1.1   PAN/PYKC 8/10/02                 Dept of EEE, Imperial College   Digital Electronics I. Slide 1.3

Points Addressed in this Lecture                                                        Electronic Representation of Data
u   What do we mean by data?                                                             u   Information can be very complicated
u   How can data be represented electronically?                                               n   e.g.:
• Numbers                         Sounds
u   What number systems are often used and why?                                                     • Pictures          Codes
u   How do number systems of different bases work?                                            n   We need a simple electronic representation                              5 Volts
u   How do you convert a number between binary and                                       u   What can we do with electronics?
Set up voltages and currents                                   R
decimal?                                                                                  n

n   Change the voltages and currents
u   A useful device is a switch                                    Switch                           V
n   Switch Closed:        V = 0 Volts
n   Switch Open:          V = 5 Volts

PAN/PYKC 8/10/02      Dept of EEE, Imperial College   Digital Electronics I. Slide 1.2   PAN/PYKC 8/10/02                 Dept of EEE, Imperial College   Digital Electronics I. Slide 1.4
u   Information can be represented by a voltage level
u   The simplest information is TRUE/FALSE
More Complex Symbols
n   This can be represented by two voltage levels:
• 5 Volts for TRUE                                                                                 u   We have seen a binary representation of information
• 0 Volts for FALSE                                                                                     n   YES / NO
n   1/0
u   A voltage signal which has only two possibilities is a BIT
n   ON / OFF
n   Bit stands for Binary Digit
u   What about more complicated information?
u   Binary means: only 2 possible values
n   COLOUR: black, red, orange, yellow, green, blue, indigo, violet.
FALSE                      TRUE                                           n   ORDINARY NUMBERS: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
(0)                      (1)                                           n   CHARACTERS: a, b, c, d, e, f, g, h, ..., x, y, z.
u   Combine bits to make words
u   Advantages of using binary representation
n   A word is a binary number containing more than one bit
n   simple to implement in electronic hardware (switch)
n   Four bit word is called "nibble", eg: 1101
n   good tolerance to noise
n   Eight bit word is called "byte", eg: 10110001

PAN/PYKC 8/10/02                    Dept of EEE, Imperial College          Digital Electronics I. Slide 1.5   PAN/PYKC 8/10/02                Dept of EEE, Imperial College   Digital Electronics I. Slide 1.7

Binary, Octal, Decimal and
Binary Coding of Information
n   [Just a quick look for now - more on these number systems later]                                     u   If we have n possibilities
u   A binary digit has only 2 possibilities                                                                        n   for the COLOURS we had 8 possibilities so n = 8
0    1                                                                                                        n   for the lower case alphabet we have 26 possibilities

u   An octal digit has 8 possibilities
0    1        2   3   4    5       6         7                                                           u   then we need log2 n bits
n   for the 8 COLOURS we need 3 bits
u   A decimal digit has 10 possibilities                                                                           n   for the lower case alphabet we need 5 bits (always round up)
0    1        2   3   4    5       6         7   8      9
u   A hexadecimal (hex) digital has 16 possibilities
0    1        2   3   4    5       6         7   8      9       A     B    C       D      E       F

PAN/PYKC 8/10/02                    Dept of EEE, Imperial College          Digital Electronics I. Slide 1.6   PAN/PYKC 8/10/02                Dept of EEE, Imperial College   Digital Electronics I. Slide 1.8
Coding Example 1 - Colours                                                                          Decimal Number System
COLOUR      Binary Code                                        5 Volts                         u   Example: 259 in decimal is                               Hundreds           Tens             Units
Black         000                                                                                            2           1               0
2 x 10 + 5 x 10 + 9 x 10                                  2                   5               9
Red          001                                R              R           R
Orange         010                                                                            u   The decimal number system is the base 10 number system
Yellow         011                                             1           0            1          n   each column represents increasing powers of 10
Green          100                                                                                 n   a subscript can be used to indicate the base of a number, eg: (259)10
Blue          101                                                                            u   In general, any number system can be used
Indigo         110                                                                                 n   base 10, base 2, base 16 and base 8 are common
Violet         111                              Setting the switches                          u   The number of different symbols used is the base
as shown generates                                 n   base 10 has 10 symbols
the code which                                     n   base 8 has 8 symbols
represent blue.                               u   Base 10 is most familiar to us
PAN/PYKC 8/10/02        Dept of EEE, Imperial College              Digital Electronics I. Slide 1.9    PAN/PYKC 8/10/02                Dept of EEE, Imperial College            Digital Electronics I. Slide 1.11

Coding Example 2 - Decimal Integers                                                                                 Binary Number System
5 Volts
Decimal    Binary Code                                                                         u   Uses 2 symbols by our previous rule
0          0000                         R           R            R             R
n   0 and 1
1          0001                                                                             u   Example: 10011 in binary is                         24          23         22          21           20
2          0010                                 1              0           0          0                 4         1           0                     1           0          0            1           1
3          0011                                                                                 1 x 2 + 1 x 2 + 1 x 2 =19
4          0100
u   Binary is the base 2 number system
5          0101
6          0110                                                                             u   Most common in digital electronics
Setting the switches
7          0111                              as shown generates
8          1000
the code which
9          1001
represent 8.
etc
PAN/PYKC 8/10/02        Dept of EEE, Imperial College              Digital Electronics I. Slide 1.10   PAN/PYKC 8/10/02                Dept of EEE, Imperial College            Digital Electronics I. Slide 1.12
Integer and Fractional Parts                                                                                                             Example
u   Binary numbers can contain fractional parts as well as                                                        u   Convert (13)10 into binary
integer parts 4 3 2 1                   -3
2    2         2      2     20       2-1 2-2     2                                       13 ÷     2   =     6 remainder      1      LSB                         Answer
3    2
1        0      0       1    1       0       1   1                                       6 ÷      2   =     3 remainder      0           .         2       2               21             20
(19.375) 10
3 ÷      2   =     1 remainder      1           .          1      1                0              1
Binary Point
1 ÷      2   =     0 remainder      1     MSB
u   This 8-bit number is in Q3 format
n   3 bits after the binary point
u   This algorithm can be extended to conversion to any base
u   How could 19.376 best be represented using an 8-bit
binary number?                                                                                                u   Other algorithms can be used as alternatives if you prefer
n   Quantization error

PAN/PYKC 8/10/02                      Dept of EEE, Imperial College           Digital Electronics I. Slide 1.13   PAN/PYKC 8/10/02                 Dept of EEE, Imperial College        Digital Electronics I. Slide 1.15

Conversion: decimal to binary                                                                                     Conversion: binary to decimal

u   Write a binary number N as                                                                                    u   The simplest way 2is to represent the binary number as
n              2              1            0                                                                  n                  1     0
n   an x 2 + ... + a2 x 2 + a1 x 2 + a0 x 2                                                                       n   an x 2 + ... + a2 x 2 + a1 x 2 + a0 x 2
u   The conversion can be done by substituting the a's with the
u   The problem is then to find the a's such that the above
expression equals N.                                                                                              given bits then multiplying and adding:
n   This can be done by repeated division of N by 2.                                                              n   eg: Convert (1101)2 into decimal
3       2        1       0
n   1 x 2 + 1 x 2 + 0 x 2 + 1 x 2 = (13) 10
u   The remainders are the binary digits starting from the Least
u   Other algorithms can be used as alternatives if you prefer
Significant Bit (LSB)

PAN/PYKC 8/10/02                      Dept of EEE, Imperial College           Digital Electronics I. Slide 1.14   PAN/PYKC 8/10/02                 Dept of EEE, Imperial College        Digital Electronics I. Slide 1.16
Binary Addition                                                                            ASCII – Representing text
1        1             1
u   First recall decimal addition                                                                       u   How to represent non-numeric information?
A                            1        2            3              4
+B                                      9            8              7           u   Use coding: American Standard Code for Information
Sum                             2        2            2              1               Interchange (ASCII) – pronounced as “askee”
u   In binary addition we follow the same pattern but                                                   u   Use 7-bits to represent alphanumeric characters
n   0 + 0 = 0 carry-out 0                                                                          u   Store in computers as 8-bit byte – 1 character/byte
n   0 + 1 = 1 carry-out 0
u   A string is a collection of characters: e.g. “hello world” is a
n   1 + 0 = 1 carry-out 0
n   1 + 1 = 0 carry-out 1                                                                              string with 11 characters (must include “space”)
1
n   1 + 1 + carry-in = 1 carry-out 1
A                             0           1              1               1
H       E    L    L       O               W O          R      L        D
+ B                             0           1              1               0               48      45   4C   4C      4F      20      57      4F   52     4C       44
Sum                               1           1              0               1

PAN/PYKC 8/10/02                Dept of EEE, Imperial College       Digital Electronics I. Slide 1.17   PAN/PYKC 8/10/02                  Dept of EEE, Imperial College        Digital Electronics I. Slide 1.19

u   Note that we need to consider 3 inputs per bit of binary
number
n   A, B and carry-in
u   Each bit of binary addition generates 2 outputs
n   sum and carry-out

PAN/PYKC 8/10/02                Dept of EEE, Imperial College       Digital Electronics I. Slide 1.18

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 6 posted: 5/25/2010 language: English pages: 6