Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 29, 2004 Lecture Number: 26.

Similar presentations


Presentation on theme: "1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 29, 2004 Lecture Number: 26."— Presentation transcript:

1 1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 29, 2004 Lecture Number: 26

2 2 Announcements Homework 7 –Due Wednesday, 11/03/2004

3 3 Review Numeric Processing Integers –One’s complement numbers –Two’s complement numbers

4 4 Outline Numeric Processing Integers –Two’s complement representation Real numbers –Representation –Limitations

5 5 Two’s Complement Positive integers have the most significant bit (leftmost) equal to 0 –The magnitude of positive numbers is the same as signed magnitude and ones complement representations Negative integers have the most significant bit (leftmost) equal to 1 –Negative numbers in n-bit two’s complement has the same binary representation as the unsigned binary number given by:

6 6 Two’s Complement Example: let n = 8, and N = 5 –There is a relationship between one’s and two’s complement numbers ones’ complement two’s complement –Two’s complement representation can be computed from a numbers one’s complement representation simple by adding one

7 7 One’s Complement It is simple to determine the representation of a negative number in one’s complement given the unsigned (magnitude) representation –Use the formula –Invert the bits It is easy to convert a one’s complement representation to a two’s complement representation by simply adding 1 to the one’s complement representation

8 8 Twos Complement

9 9 Two’s Complement Numbers Two steps –Invert bits of the magnitude representation of the number –Add one (1) to the result -7 10 Magnitude number: 7 10 Magnitude representation: 0111 Bit inversion: 1000 Add one: 1001 -7 10 in two’s complement is: 1001

10 10 Two’s Complement Mathematical operations give a correct result 4 – 3 = 4 + -3 = 1 4 0100 +(-3) +1101 1 1 0 0 0 1 1 1 Ignore the carry-out

11 11 Two’s Complement Mathematical operations give a correct result 3 – 4 = 3 + -4 = -1 3 0011 +(-4) +1100 1 1 1 1

12 12 Two’s Complement Mathematical operations give a correct result -3 – 4 = -3 + -4 = -7 -3 1101 +(-4) +1100 -7 1 0 0 1 1 1 Ignore the carry-out

13 13 Two’s Complement Numbers Solves the two problems of sign- magnitude numbers –Two representations of zero problem –Mathematical operations Give the correct result Result is in two’s complement representation

14 14 Integer Storage Integers are typically 32 bits (word size) Little-endian: intel –Most significant byte on the right Big-endian: SUN, SGI –Most significant byte on the left LSBMSB LSB


Download ppt "1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 29, 2004 Lecture Number: 26."

Similar presentations


Ads by Google