Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept 2013.

Similar presentations


Presentation on theme: "COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept 2013."— Presentation transcript:

1 COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept 2013

2 1.6 Storing Integers 1 Data Storage Two’s Complement Excess Notation Pearson Custom: Computer Science, Data Representation and Machine Concepts http://ocw.mit.edu/courses/aeronautics-and-astronautics/16-01-unified-engineering-i- ii-iii-iv-fall-2005-spring-2006/comps-programming/number_systems.pdf

3 Two’s Complement 1.6 Storing Integers Use a fixed number of bits to represent each of the values in the system First bit is used to represent the sign, 1 represents negative number, 0 represent nonnegative number A negative number is represented by inverting the bits of its corresponding positive number in each place, then add 1 to the inverted number Suppose to use 4 bits to represent the number 0111 2 = 7 10 1000 2 1001 2 = -7 10 +1

4 Two’s Complement 1.6 Storing Integers Write the two’s complement notation for -6, -3, -1.

5 Two’s Complement 1.6 Storing Integers Bit Pattern Value Represented 01117 01106 01015 01004 00113 00102 00011 00000 1111 1110-2 1101-3 1100-4 1011-5 1010-6 1001-7 1000-8 Four Bits

6 Two’s Complement 1.6 Storing Integers Addition 7 – 2 = 7 + (-2) = ? 0111 1110 + 10101

7 Two’s Complement 1.6 Storing Integers Addition 7 – 2 = 7 + (-2) = ? 0111 1110 + 10101 Use four bits 0101 2 = 5 10

8 Two’s Complement 1.6 Storing Integers Use two’s complement notation to calculate: 7 – 5 = ? -3 – 4 = ? 6 – 4 = ? -2 – 5 = ?

9 Two’s Complement 1.6 Storing Integers What is the range of numbers that can be represented using the 2’s complement? Answer: 2 N-1 – 1 to -2 N-1 Three bits: 3 to -4 Four bits: 7 to -8 Eight bits: ? N is the number of bits

10 Two’s Complement 1.6 Storing Integers List all the number with the two’s complement notation using 3 bits Express 16 - -16 with the two’s complement notation using 8 bits

11 Two’s Complement 1.6 Storing Integers Overflow Calculate 5 + 4 with two’s complement notation using 4 bits

12 Excess Notation 1.6 Storing Integers Steps: 1.Add the excess value 2 N-1 to the number, where N is the number of bits used 2.Convert the resulting number into binary format Suppose use 4 bits -6 +8 2 4-1 = 20010

13 Two’s Complement 1.6 Storing Integers Write -8 to 7 with excess notation with 4 bits Write -4 to 3 with excess notation with 3 bits


Download ppt "COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept 2013."

Similar presentations


Ads by Google