The alternate reality of the 10s complement code
 

Imagine that humans do not use the signed representation for signed values, but instead used the 10s complement representation:

   We do NOT use:        Instead we use:
  ----------------      -----------------      
      ...                     ...
       -3                     997
       -2		      998
       -1		      999
        0		      000
	1		      001
	2		      002
	3		      003
      ...		      ...
   

How would we teach kids to add and subtract ???

The alternate reality of the 10s complement code
 

Answer:   we don't need to make special rules when operands are negative !!!

   In a world using the 10s complement representation:

      56     is represented by:        056
      neg 34 is represented by:        966

   And:   56 + (neg 34) is computed as:      056
                                          +  966
                                         -------
                                             022

   We would know that 022 represents the value 22 !!  

   And the addition:  56 + (neg 34) = 22 is correct !
   

Overflow

Important fact:

  • The 3 digit 10s complement code can only represent signed values in the range [−500, 499]

  • If a result is outside this range, the result will be incorrect

    We call this an overflow condition

Example overflow:

       250  (positive 250)
     + 400  (positive 400)
     -----
       650   ---> represents negative 350  


   positive 250 + positive 400 = positive 650
                               ≠ negative 350 !!
   

Overflow

Solving/preventing the overflow problem:   use a longer 10s compl code

  • A 3 digit 10s complement code can represent values in the range [−500, 499]

  • A 4 digit 10s complement code can represent values in the range [−5000, 4999]

  • And so on...

 

We must use an adequate length code than can represent all the values that we will need

(Note: This length choice will come up again when we discuss the 2s complement code - you will have to pick a correct length by picking the correct type of variables, i.e.: byte, short, int and long)