Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Representation.

Similar presentations


Presentation on theme: "Data Representation."— Presentation transcript:

1 Data Representation

2 Data Representation Input data transformed into output.
A computer is a device that: Accepts input Processes data Stores data Produces output Input data transformed into output. Data can be stored for repeated output.

3 Data Representation Spreadsheet data  graphs 3D models  animation Vocals and MIDI  Song Bar code  Price of item Card and Pin #  Money from ATM

4 Data Representation How can we represent information in a way that can be stored and manipulated by a computer?

5 Data Representation and Storage
External representation: computers use decimal digits (base ten), 26-character alphabet for easier human interaction via keyboard, terminal, printer Internal representation: computers use binary system for numbers, letters, graphics, etc.

6 Data Representation Internally, computers represent information as patterns of bits A bit (binary digit) is either 0 or 1; these are symbols and have no numeric meaning Storing a bit requires that a device can be in one (and only one) of just two states; analogous to true and false

7 Data Representation Binary Numbers!!! Sound  pitch  number  binary number Letter  number  binary number Image  color at each pixel  number  binary number

8

9 Decimal Number Systems
Base 10 Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 e.g = = 3 x x x100 = 3 x x x 1 =

10 Binary Number System Base 2 Digits 0, 1 e.g. 1102 =
= 1 x x x 20 = 1 x x x 1 = = 6

11 Data Representation Solution: use a fixed number of digits.
But how many bits do we need? 1 binary digit  0 or 1  2 possible chars 2 binary digits  00, 01, 10, 11  4 chars 3 binary digits  000, 001, 010, 011, 100, 101, 110, 111  8 chars Notice a pattern? 12, 24, 38, … the total number of character that can be represented by n bits is 2n

12

13 Data Representation log2n
But how many bits are needed to store n symbols? Or, how many bits are needed to represent n numbers? log2n How many bits do we need to represent 16 states, 63 states?

14 Let’s count 1 bit 2 bits 3 bits 000 ;0 001 ;1 010 ;2 011 ;3 100 ;4
; 0 ; 1 2 bits ; 0 01 ; 1 10 ; 2 ;3 3 bits ;0 ;1 ;2 ;3 ;4 ;5 ;6 ;7

15 Binary Numerals: Convert to Decimal
Bits are numbered from the right b7 b6b5b4b3b2b1b0 Subscripts represent the place value bi has place value 2i Convert to decimal b7 * 27+b6*26 + b5*25 +b4*24 +b3*23 +b2*22 +b1*21 + b0*20

16 Binary to Decimal: Example
100 = 1 * * = 1 *

17 Data Representation Binary to Decimal = 1 * * * * * 20

18 Data Representation Binary to Decimal = 1 * * * * * 20 = = 19

19 Converting Decimal to Binary
Repeatedly divide by 2, recording remainders in reverse order e.g. 53 / 2 = 26 R 1 26 / 2 = 13 R 0 13 / 2 = 6 R 1 6 / 2 = 3 R 0 3 / 2 = 1 R 1 1 / 2 = 0 R 1 giving

20 Excercise 56d = ?b 1011b = ?d

21 Addition & Subtraction
=? = 011 – 010 =

22 4 bits and Hex 0000 ;0 1000 ;8 0001 ;1 1001 ;9 0010 ;2 1010 ;10 (Ah)
;0 ;1 ;2 ;3 ;4 ;5 ;6 ;7 ;8 ;9 ;10 (Ah) ;11 (Bh) ;12 (Ch) ;13 (Dh) ;14 (Eh) ;15 (Fh)

23 Storing Negative Values Two’s complement!

24 Storing Negative Values
Sign Magnitude use first bit as sign bit, 0 = positive 1 = negative e.g. 8-bits = = −0 = = −1 … … = = −127 Problem: has two 0s. Using 2’s Complement instead

25 Two’s Complement Two’s complement if positive, use binary
if negative, complement bits and add one e.g. −53 magnitude (binary rep for 53) complement (flip each bit) add (add 1, resulting 2’s complement rep for -53)

26

27 Examples: 2’s Complement Rep
3 bit pattern 000 ; 0 001 ; 1 010 ; 2 011 ; 3 100 ; -4 101 ; -3 110 ; -2 111 ; -1 We can use the 2’s complement code of 3 code to find that of -3 And vice versa

28 Exercise Practice: 2 – 3 using 2’s complement representation as done by a computer Using 3 bit pattern (2) (-3) = (-1) Using 8 bit pattern (2) (-3) = (-1)

29 8-bit Two’s Complement = = = − = = −2 … … = = − = −128

30 16-bit Two’s Complement 8-bit two’s complement range is − 27 to 27 − 1 − to 127 16-bit two’s complement range is − to 215 − 1 − 32,768 to 32,767

31 Overflow When a number is too big for the range, overflow will occur
Example: with 3 bit pattern 3 + 2 using 2’s complement Two positive number add up to a negative number, overflow Similarly, -4-3 results in a positive number, also overflow

32 Representing Real Numbers

33 Representing Real Numbers
A number with a whole part and a fractional part , , 37.0, and Positions to the right of the decimal point are the tenths position: 10-1, 10-2 , Same rules apply in binary as in decimal Decimal point is actually the radix point Positions to the right of the radix point in binary are 2-1 (one half), 2-2 (one quarter), 2-3 (one eighth)

34 Representing Real number
A real value in base 10 can be defined by the following formula The representation is called floating point because the number of digits is fixed but the radix point floats A binary floating-point value is defined by the formula

35

36 Memory Sizes A byte is 8 bits. Kilobyte (K) = 210 = 1,024 bytes
Megabyte (Mb) = 220 = 1,048,576 bytes Gigabyte (Gb) = 230 = 1,073,741,824 bytes

37 Character Representation

38 Character Representation
Assign a code to each character ASCII American Standard Code for Information Interchange 8 bits per character 256 possible codes with 8 bits Unicode, 16 bits per character International language coding standard Superset of ASCII

39 ASCII American Standard Code for Information Interchange (ASCII ) defines 256 symbols that can be stored in a byte. Each symbol corresponds to a number from Symbol Decimal Binary @ 64 A 65 B 66 C 67 D 68 E 69 F 70 G 71 H 72

40 ASCII Code Code Value Letter 0 Null character Special Control Characters 10 \n = New line 32 Space 33-47, 58-64, Punctuation A - Z a - z

41 Digits 0 through 9 in ASCII
Digit Dec Hex … … …

42 Unicode Character Examples


Download ppt "Data Representation."

Similar presentations


Ads by Google