Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 2  Complement  Floating Point Number  Character Encoding.

Similar presentations


Presentation on theme: "1 Lecture 2  Complement  Floating Point Number  Character Encoding."— Presentation transcript:

1 1 Lecture 2  Complement  Floating Point Number  Character Encoding

2 2 Complement Complement as a representation of negative number More commonly used 1’s complement 2’s complement (used in Personal Computer)

3 3 Complement (for binary) 1’s complement 1’s complement of a number is just to change 0 to 1 and 1 to 0. e.g. 10 0100 => 1’s complement is 01 1011 2’s complement 2’s complement of a number is just to add 1 to its 1’s complement e.g. 10 0100 => 2’s complement is 01 1100

4 4 Example - Complement Consider the binary number 100 0110 it’s 1’s complement is 011 1001 it’s 2’s complement is 011 1010 How to differentiate whether a binary number is positive or negative? * Use a leading zero for positive number! Why?

5 5 1’s complement Arithmetic Positive Number + Negative Number Result is a positive number Result is a negative number Positive Number + Positive Number Overflow (explain in slide 24) Negative Number + Negative Number Underflow (explain in slide 25) Note: Convert the negative number to 1’s complement before any calculation e.g. 10 + (-8) => 0 1010 + 1 0111 1’s complement of 0 1000

6 6 1’s Complement Arithmetic Positive Number + Negative Number Result is a positive number (rotate) e.g.10 + (-8) 0 1010 0 0001 + 1 0111+1 10 0001 0 0010 Rotate Answer is 2 10

7 7 1’s Complement Arithmetic Positive Number + Negative Number Result is a positive number (Rotate) Result is a negative number (How do you know the result is negative? ) Example 8 + (-10) 0 1000 +1 0101 1 1101 Negative Number (used 1’s complement to get the value)

8 8 1’s Complement Arithmetic Positive Number + Positive Number Overflow Example 8 + 9 = 17 0 1000 +0 1001 1 0001 => -14 It may be wrongly interpreted as a negative number. So, we call this case as overflow.

9 9 1’s Complement Arithmetic Negative Number + Negative Number underflow Example (-8) + (-9) = -17 1 0111 +1 0110 0 1001 => 9 It may be wrongly interpreted as a positive number. So, we call this case as underflow.

10 10 2’s complement How to calculate 2’s complement. Add 1 to 1’s complement 1110 0011 1’s Complement 0001 1100 2’s Complement 0001 1101

11 11 2’s complement Arithmetic Positive Number + Negative Number Result is a positive number Result is a negative number Positive Number + Positive Number Overflow Negative Number + Negative Number Underflow Note: Convert the negative number to 1’s complement before any calculation e.g. 10 + (-8) => 0 1010 + 1 1000 2’s complement of 0 1000

12 12 2’s Complement Arithmetic Positive Number + Negative Number Result is a positive number (Discard) e.g.10 + (-8) 0 1010 + 1 1000 10 0010 Discard 0 0010 Answer is 2 10.

13 13 2’s Complement Arithmetic Positive Number + Negative Number Result is a negative number Example 8 + (-10) 0 1000 +1 0110 1 1110 Negative Number (used 2’s complement to get the value)

14 14 2’s Complement Arithmetic Positive Number + Positive Number Overflow Example 8 + 9 = 17 0 1000 +0 1001 1 0001 => -15 It may be wrongly interpreted as a negative number. So, we call this case as overflow.

15 15 2’s Complement Arithmetic Negative Number + Negative Number underflow Example (-8) + (-9) = -17 1 1000 +1 0111 0 1111 => 15 It may be wrongly interpreted as a positive number. So, we call this case as underflow.

16 16 Example - Arithmetic with complement Example for 1’s complement arithmetic Example 1 Example 2Example 3

17 17 Example - Arithmetic with complement Example for 2’s complement arithmetic Example 1 Example 2 Example 3

18 18 Floating-point Numbers IEEE Standard 754 Floating Point Representation Represent real number in scientific notation Represent a number with a base and exponent i.e. 0.00001101 =>1.101 x 2 -5 base exponent

19 19 Floating-point Number Advantages Possible to represent a very large and very small number e.g.10 +100 10 -100 It will not lose precision (due to round-off) CPU will have instruction (low level command to support floating point calculation – e.g. co-processor)

20 20 Floating-point Number Format Three basic components: the sign, the exponent [ 指數 ] and the mantissa [ 尾數 ] For a 32-bit floating point number

21 21 Floating-point Number Sign Bit Zero denotes a positive number; one denotes a negative number. Exponent Bias is used (so we can differentiate between positive and negative) e.g. for 32 bits, bias is -127 and for 64 bits bias is 1023. (???????Bias) exponent > 127 ==> positive exponent exponent negative exponent *127 10 = 0111 1111 2

22 22 Floating-point Number Mantissa It must be normalized (i.e. it must in the format of 1.XXXX) So, the one before the decimal can be assumed. e.g. 100.100mantissa is 00100 Do you know why? Exponent => 2 so mantissa is 1.00100 Assume the 1 before decimal => 00100 Check the 64-bit floating point standard yourselves!

23 23 Floating Point Number Steps 1. Convert the number to binary 2. Convert the binary number to normalized form 3. Find out the sign, exponent and mantissa

24 24 Floating-point Number Example Number: +101011.0101 Sign bit: 0 Normalized Mantissa (23 bits): (E.g. 1.010110101)  010 1101 0100 0000 0000 0000 Exponent (8 bits): 1000 0100 (127 + 5 = 132 10 ) Floating Point: 0 1000 0100 010 1101 0100 0000 0000 0000 SignExponent Mantissa

25 25 Character Representation Binary Code Decimal ‘0’ - ‘9’ by 4-bits code Easy conversion to decimal digits for printing or display Faster decimal calculations Extended Binary Coded Decimal Code (EBCDIC) 8-bits code to represent more characters

26 26 Character Representation American Standard Code for Information Interchange (ASCII) - 7 bits Define a vendor-independent character coding system (including some control character e.g. Esc code for printer) Support data communication between computers and peripheral / telecommunication device Note: The character will be stored in form of ASCII code

27 27 ASCII Table

28 28 Multinational Character Korea, Japan, Chinese and Vietnamese Characters Unicode (Version 5.1) (CKJV) http://www.unicode.org/versions/Unicode5.1.0/ Big5 (Taiwan) for Traditional Chinese Character GB (China) code for Simplified Chinese character

29 29 Character Encoding

30 30 Unicode Start  Program  Accessories  System Tools  Character Map


Download ppt "1 Lecture 2  Complement  Floating Point Number  Character Encoding."

Similar presentations


Ads by Google