Presentation is loading. Please wait.

Presentation is loading. Please wait.

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.

Similar presentations


Presentation on theme: "King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department."— Presentation transcript:

1 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 1 © 2005 Dr. Abdelhafid Bouhraoua COE 205 Lecture 5: Data Representation

2 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 2 © 2005 Dr. Abdelhafid Bouhraoua COE 205 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)

3 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 3 © 2005 Dr. Abdelhafid Bouhraoua COE 205 What need to be represented From CPU point of view:ONLY Binary To Standardize: At CPU Level Need to represent: 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 Represent ONLY Numbers and Characters

4 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 4 © 2005 Dr. Abdelhafid Bouhraoua COE 205 Numbering Systems N = d w-1 B w-1 +…+ d i B i + d 1 B 1 +d 0 B 0 d i : digits;B: Base d i in [0, B-1] Numbering SystemBaseDigits Set Binary20, 1 Octal80, 1, 2, 3, 4, 5, 6, 7 Decimal100, 1, 2, 3, 4, 5, 6, 7, 8, 9 Hexadecimal160, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F (728) 10 = (1011011000) 2 = (1330) 8 = (2D8) 16 728d = 1011011000b = 1330o = 2D8h

5 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 5 © 2005 Dr. Abdelhafid Bouhraoua COE 205 Number Conversion Binary - Hexadecimal Hexa- decimal Bin.Sym. 00000 00011 00102 00113 01004 01015 01106 01117 10008 10019 1010A 1011B 1100C 1101D 1110E 1111F Binary to Hexadecimal 000100110100110101101100 0 134D6C Conversion Table Lookup Hexadecimal to Binary 5D1F8 0101 1101 0001 1111 1000 Conversion Table Lookup Octal Bin.Sym. 0000 0011 0102 0113 1004 1015 1106 1117 Binary to Octal 001110101101100 0 00 0 16554 Octal to Binary 5361 Conv. Table Lookup 101 011 110 001 Hex  Octal: Go to Binary First

6 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 6 © 2005 Dr. Abdelhafid Bouhraoua COE 205 Number Conversion Decimal – Binary, Octal, Hex Binary, Octal, Hex  Decimal: –Represent the number in base 10 and compute the operations: –110110b = 1x2 5 + 1x2 4 + 0x2 3 + 1x2 2 + 1x2 1 + 0x2 0 = 54 –236o = 2x8 2 + 3x8 1 + 6x8 0 = 158 –3Ch = 3x16 1 + Cx16 0 = 60 Decimal  Binary, Octal, Hex –Remainder Set of Successive Division by Target Base (2, 8 or 16) N = Q 0 x 2 + R 0 First Division Q 0 = Q 1 x 2 + R 1 Second Division Q 1 = Q 2 x 2 + R 2 Third Division …. Q n-1 = 0 x 2 + R n Cannot divide anymore N = (((((…(R n x2) x 2 + R n-1 ) x 2 +.) x2 + …..x2 + R 1 ) x2 + R 0 N = R n x 2 n + R n-1 x 2 n-1 + ….. + R 1 x 2 + R 0

7 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 7 © 2005 Dr. Abdelhafid Bouhraoua COE 205 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

8 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 8 © 2005 Dr. Abdelhafid Bouhraoua COE 205 Number Representation Numbers in computers –Just a representation of real numbers –Real numbers have an infinite number of digits 153 ten = …..00000…0000010011001 two = 0000 0000 1001 1001 two in a 16 bits word Add, Subtract, Multiply, Divide Result bigger than number of available slots (bits) Overflow

9 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 9 © 2005 Dr. Abdelhafid Bouhraoua COE 205 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

10 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 10 © 2005 Dr. Abdelhafid Bouhraoua COE 205 Sign and Magnitude Intuitive Representation: Sign + Magnitude SignMagnitude Range [-2 n-1 -1, +2 n-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

11 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 11 © 2005 Dr. Abdelhafid Bouhraoua COE 205 One’s Complement Negative numbers are bit-to-bit complements of positive numbers –+9 on 8 bits = 00001001 –-9 on 8 bits = 11110110 Range [-2 n-1 -1, +2 n-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

12 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 12 © 2005 Dr. Abdelhafid Bouhraoua COE 205 Two’s Complement Range [-2 n-1, +2 n-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). 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)

13 King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Lecture 5 – Data Representation 13 © 2005 Dr. Abdelhafid Bouhraoua COE 205 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


Download ppt "King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department."

Similar presentations


Ads by Google