Representing negative values: the sign-magnitude representation system

  • Humans represent negative values using a minus (−) sign in front of the number:

       2   (or:  +2) represents  positive 2
      -2             represents  negative 2 
    

  • This representation is called:

    • The sign-maginitude representation


  • The sign-maginitude representation consists of:

    1. A sign component representing the sign (positive/negative) of the (signed) number

    2. A magnitude component representing the absolute value of the (signed) number

Denoting the intrinsic values

I use black dots to represent the intrinsic positive values:

I use red dots to represent the intrinsic negative values:

The mapping between the sign-magnitude representation and the signed values
 

The following table depicts the mapping between the sign-magnitude representation and the signed intrinsic values:

 
 Sign-
 magnitude                                 0   
 representation:   ...  -4   -3   -2  -1  -0   1    2    3   ... 
                 ---------------------------------------------  
 Intrinsic value:      ••••  •••  ••   •  ( )  •   ••   •••
   

The red dots represent negative values

Short-comings of the sign-magnitude representation

There are 2 short-comings with the sign-magnitude representation:

  1. There are 2 ways to represent (= write) the value ZERO:

    1.     0
    2.   −0

  2. The meaning of arithmetic operation performed depends on the values in the operation:

               4                     4
           +   3                 +  -3
         ---------            ----------
               7                     1
    
       We added 4 and 3       we subtracted 4 and 3 ! 
    

    So the meaning of the + opertion changes depending on the value of the operands

    (This results in more complex computational circuitry to perform the computation)

The sign-magnitude representation in binary

We can implement the the sign-magnitude representation for binary numbers as follows:

  • The sign-magnitude representation for binary data:

    • The left-most bit in the binary number represents the sign:

          0.............   ===> a positive binary number
          1.............   ===> a negative binary number
      

    • The remaining bits are used to represent the magnitude (= absolute value) of the number

  • Examples of sign-magnitude representation using 8 bits:

        00000111    represents +7 (= 7)
        10000111    represents -7                         

Problems with the sign-magnitude representation
 

Problem 1:

  • There are 2 different representations for the value 0    

Example in 8 bits:

    Representation 1:  00000000 (+0) 
    Representation 2:  10000000 (-0)    
   

This phenomenon complicate the testing for 0 (i.e.: value in variable == 0)

Problems with the sign-magnitude representation
 

Problem 2:

  • The meaning of some arithmetic operations depends on the value of the operands

Example in 8 bits:

         00000011     (=  +310)      
       + 10000001     (=  -110)
     ------------
         00000010     (=  +210)
   

The operation is add (+), but we obtained the answer 00000010 using a subtraction:   0000011 − 0000001
I.e.: the computer must use a subtraction circuit to perform the "addition" !!

A bit of computer history
 

Once upon a time, some computers had used the sign-magnitude representation

  • Computers (in the past) that used the sign-magnitude representation for signed values must use more complex arithmetic circuits !!!

  • Disadvantage of using the sign-magnitude representation:

      • The use of more complex digital circuitry to perform arithmetic operations (because we must use the sign of the operand to determine which operation that need to be performed !!!)

 

 

All modern computers use the 2s complement code to represent signed integer values

We will discuss the 10s complement code first as prelude to the 2s complement code....