Menu
Log in

Computer Engineering Concepts

2.5 Negative Numbers

Negative numbers are an essential aspect of computing because they are used widely in a variety of applications. The representation of negative numbers in binary is needed to handle mathematical calculations involving negative numbers. A systematic representation of the negative is needed because the computer is only able to process 1's and 0's, therefore the negative (-) needs to be represented using 1's and 0's.  There are different approaches to the representation of negative numbers: the sign magnitude method, the ones complement method, and the two’s complement method. These methods use different approaches to representing negative numbers, therefore before a binary number can be interpreted, the method of representation must be known.

The Sign Magnitude Representation

In this method, representing positive and negative numbers in terms of 1's and 0's can be approached by assigning each case to one of the two binary symbols. Consider the number 100111 with 6bits, and let us create the negative by adding an extra bit on the left to indicate the sign of the number. The number with the extra bit will be _100111 (_ indicates the extra bit which can be either 1 or 0), and the extra bit will indicate the sign. Let us now assign + as 0 and - as 1, thus making the potential negative representation 1100111 and the positive representation 0100111. In this approach the left most bit represents the sign and the rest of the bits represent the magnitude of the number. In this method 1100111 represents -19 and should not be interpreted as 103, which is a direct conversion of the binary representation to decimal.

Though this method is easy to implement and understand, it creates a mathematical problem in that it does not satisfy the condition of x + (-x) = 0. This concept of a positive and a negative number adding up to give zero is not satisfied in this method of representation. For example in this case, 19 + (-19) = 0, but when the operation is performed using the binary numbers in the sign magnitude representation the algebraic rule does not hold as shown below.


The result of this system of representation unfortunately does not meet the mathematical requirement of the result being equal to 0000000.

The One’s Complement Representation

In the ones complement method the negative number is represented using the complement. The complement or the ones complement is a simple switch of the ones to zeros and the zeros to ones. If the number is 0101011, then the complement is 1010100. Using this approach 7 represented using is 4 bits is 0111, and -7 would be represented as 1000.

This approach also meets the same challenges as the sign magnitude method in that it does not meet the mathematical requirement of a number and its negative adding up to produce 0, instead it produces 1s, as shown below.


The Two’s Complement Representation

Though this method may seem a bit involved, it is the preferred method of representation. In this method of representing negative numbers in binary, the algebraic rule of x + (-x) = 0 remains valid. The process is started by finding the ones complement of the number. Here the complement by itself is not the negative representation of the number because when the number and the complement are added together it will produce a set of 1's instead of 0's. To solve this problem a 1 is added to the complement to produce the two’s complement, and this now becomes the negative representation of the number. As in the sign magnitude representation, the left most bit is still responsible for the sign of the number. If the left most bit is 1, then the number is a negative number and if the left most bit is 0 then the number is a positive number.

Consider the example of 100111 which can be written as 0100111 with the extra bit added on for the sign (Note: leading zeros in a number does not change its value). The complement of 0100111 will be 1011000(the ones and zeros are switched). Adding 1 to the complement 1011000 results in 1011001, which is referred to as the two’s complement. The sum of the initial number and the two’s complement results in a binary value of 10000000. If the result is represented using 7 bits like the initial number instead of 8 bits, then the result turns out to be 0000000 which is consistent with the mathematical requirement of the sum of a number with its negative equaling zero.

Example I:        Find the negative of 10011 using the two’s complement method assuming that 8 bits are available.

Solution:          The number 10011 expressed using 8 bits would be 00010011. The complement of the 8 bit representation would be 11101100. The 1's and the 0's are switched. Now a 1 has to be added to the complement two produce the two’s complement.

Two’s complement 

Therefore the negative of 10011 is 11101101

Check:                         

Since only 8 bits are used the leftmost or the 9th bit is neglected to give 00000000


Since this method can lead to some confusion as to whether 11101101 is -19 or +237, the solution to this ambiguity is based on a clear definition of what it represents.. If it is known that the number is represented using the twos complement, then 11101101 represents -19 only. Thus solving the ambiguity problem. To find the decimal value of a negative binary number the reverse process is applied.

Example II:       Convert 11111001 to decimal if the number is represented using the two’s complement method.

Solution:

                             

                              Inverting the result 00000100 =100 = 4


The use of the left most bit does not change the amount of numbers that can be represented, but rather it changes range of the numbers. For example, consider 4 bits used to represent numbers. If all the numbers that are represented are positive, then the range of numbers that can be represented is 0 to 15 (24 -1=15). If the left most bit is used to represent the sign as in the sign magnitude method, then the range of numbers becomes –8 to +7. In both cases a total of sixteen numbers can be represented.

Table 2.3 compares the three different methods of representation. With 3 bits there are a total of 8 possible bit arrangements, thus allowing for 8 different numbers to be represented. Each method simply assigns the numbers differently.


Table 2.3 Comparison of negative number representation methods.


2.5 Practice Questions

1.     Represent the following negative numbers using the sign magnitude method. Assume 8 bits are used to represent the numbers.

        a. -5                    b. -13                  c. -27    d. -38                 

2.     Represent the following negative numbers using the 2's complement method. Assume 8 bits are available to represent the numbers.

        a. -9                    b. -14                  c. -23    d. -43                 

3.     Convert the following sign magnitude representation to decimal. Assume the left bit represents the sign.

        a. 101101          b. 111100          c. 010111 d. 0010111       

4.     Convert the following 2's complement representation to decimal.

        a. 110001           b. 111101          c. 1101100 d. 1100100       

5.     Explain why the two’s complement representation is more useful than the sign magnitude representation in computing.





GlobalEduTech Solutions

Powered by Wild Apricot Membership Software