IT1004: Data Representation and Organization Negative number representation
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 = (in 8 bits) -37 = (in 8 bits) 2 What is the range of numbers that can be represented in this method?
Sign-Magnitude Representation… Example 2: +127 = (in 8 bits) = (in 8 bits) Example 3 : 0= (in 8 bits) if we consider negative value of this bit stream we get 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
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
One’s complement The range of 8-bit one's complement integers is -127 to Exercises: Find the 1’s complement of ABC
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: (17) (-8 ) = ( 9 ) 8 10 =
Two’s complement number representation
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
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 = Example 3: Using an 8 bit representation 24 base 16=
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 …………..First, invert the bits …………..Then, add 1 = The 2’s complement of is
Two’s complement… Example 3: (4 bits) Represent -3 in 2's complement +3 ……………………0011 complement …….1100 add 1 ……………… = 1101 Example 2 : (4 bits) Represent -6 in 2's complement +6 ……………………0110 complement …….1001 add 1 ……………… = 1010 Example 4: (5 bits) Represent -13 in 2's complement +13 ………………… complement … add 1 …………… = 10011
Two’s complement… Represent the following numbers in two’s complement form using 5 bits Represent the following numbers in two’s complement form using 8 bits
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 …… …… …… …… ……… ……… Examples: 5 bits 8 ……… ……… ………
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
Addition and subtraction in 2's complement notation Example: 4 bits 15 6 ……… ……… ……… ……… ……… 1000 X This means a negative number Here we can get the correct answer by increasing the number of bits
Addition and subtraction in 2's complement notation Example: 5 bits 16 6 ……… ……… ……… ……… ……… √
Addition and subtraction in 2's complement notation… Perform the following calculations in two’s complement method using 5 bits Perform the following calculations in two’s complement method using 8 bits
Polynomial Evaluation Whole Numbers (Radix = 10): = 1 10 0 With Fractional Part (Radix = 10): = 3 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