Presentation is loading. Please wait.

Presentation is loading. Please wait.

IT1004: Data Representation and Organization Negative number representation.

Similar presentations


Presentation on theme: "IT1004: Data Representation and Organization Negative number representation."— Presentation transcript:

1 IT1004: Data Representation and Organization Negative number representation

2 Sign-Magnitude Representation This is one method used to represent negative numbers in Binary Here an extra digit is placed in front the existing binary number to represent the sign If this extra digit is a '1', it means that the rest of the digits represent a negative number If the extra digit is a 0', it means that the number is a positive Example : +37 = 00100101 (in 8 bits) -37 = 10100101 (in 8 bits) 2 What is the range of numbers that can be represented in this method?

3 Sign-Magnitude Representation… Example 2: +127 = 01111111 (in 8 bits) - 127 = 11111111 (in 8 bits) Example 3 : 0= 00000000 (in 8 bits) if we consider negative value of this bit stream we get 10000000 This is also representing zero This is a drawback of Sign-Magnitude representation (That is two values to represent zero as +0 and -0) 3

4 One’s complement One's complement number representation is used for signed numbers in binary format To obtain the 1's complement of a number: – Get the binary format of the given number – Complement all the bits in the binary number there are different representations for +0 and -0 in one's complement. Examples of 8-bit one's complement numbers: BIT PatternDecimal ValueBIT PatternDecimal Value 0000 +00000 0011+3 1111 -01111 1100-3 0000 0001+10001 1111+31 1111 11101110 0000-31

5 One’s complement The range of 8-bit one's complement integers is -127 to +127. Exercises: Find the 1’s complement of 1.45 10 2.37 10 3.ABC 16 4.123 8 5.45 8

6 Addition in One’s complement Addition of signed numbers in one's complement is performed using binary addition with end-around carry. If there is a carry out of the most significant bit of the sum, this bit must be added to the least significant bit of the sum. To add decimal 17 to decimal -8 in 8-bit one's complement: 0001 0001(17) 1111 0111(-8 ) 1 0000 1000 1 0000 1001 = ( 9 ) 8 10 = 0000 1000 2

7 Two’s complement number representation

8 Two’s complement Two's complement number representation is used for signed numbers on most modern computers. This notation allows a computer to add and subtract numbers using the same operations We can illustrate two's complement notation as follows: – A fixed number of bits are used to represent numbers – The most significant bit is called the sign bit – This same notation is used to represent both positive and negative numbers

9 Two’s complement… Positive numbers are represented normally Example 1: Using a 4 bit representation 5 in 2's complement = 0101 Example 2: Using an 8 bit representation 5 in 2's complement = 00000101 Example 3: Using an 8 bit representation 24 base 16= 0010 0100

10 Two’s complement… To obtain the 2's complement of a number: – Complement the bits – Add one to the result Negative numbers Are represented using a 2's complement form Example1 : Find the 2’s complement of the following 8 bit number 00101001 11010110 …………..First, invert the bits + 00000001 …………..Then, add 1 = 11010111 The 2’s complement of 00101001 is 11010111

11 Two’s complement… Example 3: (4 bits) Represent -3 in 2's complement +3 ……………………0011 complement …….1100 add 1 ………………..0001 -3 = 1101 Example 2 : (4 bits) Represent -6 in 2's complement +6 ……………………0110 complement …….1001 add 1 ……………… 0001 -6 = 1010 Example 4: (5 bits) Represent -13 in 2's complement +13 ………………… 01101 complement …. 10010 add 1 …………… 00001 -13 = 10011

12 Two’s complement… Represent the following numbers in two’s complement form using 5 bits 1. -5 2. -7 3. -4 4. -11 5. -3 Represent the following numbers in two’s complement form using 8 bits 1. -12 2. -18 3. -21 4. -19 5. -9

13 Addition and subtraction in 2's complement notation Addition is performed by doing the simple binary addition of the two numbers. Subtraction is accomplished by first performing the 2's complement operation on the number being subtracted and then adding the two numbers. 13 8 …….01000 +4 ……00100 12 ……01100 -8..…….. 11000 + -4 ………. 11100 -12 ………. 10100 Examples: 5 bits 8 ……….. 01000 + -4 ………. 11100 4 ……….. 00100

14 Addition and subtraction in 2's complement notation Since we are working with numbers contained in a fixed number of bits, we must be able to detect overflow following an operation. No overflow occurs when the value of the bit carried into the most significant bit is the same as the value carried out of the most significant bit. Overflow occurs when the value of the bit carried into the most significant bit is not the same as the bit carried out of the most significant bit. 14

15 Addition and subtraction in 2's complement notation Example: 4 bits 15 6 ……… 0110 + 1 ……… 0001 7 ……… 0111 + 1 ……… 0001 8 ……… 1000 X This means a negative number Here we can get the correct answer by increasing the number of bits

16 Addition and subtraction in 2's complement notation Example: 5 bits 16 6 ……… 00110 + 1 ……… 00001 7 ……… 00111 + 1 ……… 00001 8 ……… 01000 √

17 Addition and subtraction in 2's complement notation… Perform the following calculations in two’s complement method using 5 bits 1. 10-5 2. -7+3 3. -4 +1 4. -11+ 8 5. -3+4 Perform the following calculations in two’s complement method using 8 bits 1. -12+7 2. -18+9 3. 22-21 4. -19+11 5. -9+5

18 Polynomial Evaluation Whole Numbers (Radix = 10): 1234 10 = 1  10 3 + 2  10 2 + 3  10 1 + 4  10 0 With Fractional Part (Radix = 10): 36.72 10 = 3  10 1 + 6  10 0 + 7  10 -1 + 2  10 -2 General Case (Radix = R): (S 1 S 0.S -1 S -2 ) R = S 1  R 1 + S 0  R 0 + S -1  R -1 + S -2  R -2


Download ppt "IT1004: Data Representation and Organization Negative number representation."

Similar presentations


Ads by Google