Interpreting 10s complement codes
 

Humans are trained to represent signed values using the sign-magnitude rperesentation:

 

Interpreting 10s complement codes
 

We have just learned a new representation for signed values:

 

Interpreting 10s complement codes
 

Question:   how do we convert between these 2 representations ?

 

Note: the conversion must preserve the represented value !!

Converting a sign-magnitude code into a (3 digit) 10s complement code
 

Question:   what's the (3 digit) 10s compl code for 34 and −34 ?

Consider the mapping that we discussed previously:


   3 digit
   10s compl code      
   (odometer code)             
           500     996 997 998 999 000 001 002 003 004     499
            +---+...+---+---+---+---+---+---+---+---+...+---+    
                   •••• ••• ••    ( )  •   ••  ••• ••••
          -500     -4  -3  -2  -1   0   1   2   3   4      499
  Signed value                    
   

We must consider 2 cases:
      (1) when the value is positive (or ZERO)   and
      (2) when the value is negative

Converting a sign-magnitude code into a (3 digit) 10s complement code
 

How to encode (= represent) a positive value as a (3 digit) 10s complement code:

 


   3 digit
   10s compl code      
   (odometer code)             
           500     996 997 998 999 000 001 002 003 004     499
            +---+...+---+---+---+---+---+---+---+---+...+---+    
                   •••• ••• ••    ( )  •   ••  ••• ••••
          -500     -4  -3  -2  -1   0   1   2   3   4      499
  Signed value                    
   

Converting positive values (and ZERO):
      Prepend the sign-magnitude code with leading ZEROs until you have 3 digits

Example:   the (3 digit) 10s compl code for 34 is:   034

Note:   adjust the number of leading ZEROs to the length of the 10s complement code

Converting a sign-magnitude code into a (3 digit) 10s complement code
 

How to encode (= represent) a negative value as a (3 digit) 10s complement code:

 


   3 digit
   10s compl code      
   (odometer code)             
           500     996 997 998 999 000 001 002 003 004     499
            +---+...+---+---+---+---+---+---+---+---+...+---+    
                   •••• ••• ••    ( )  •   ••  ••• ••••
          -500     -4  -3  -2  -1   0   1   2   3   4      499
  Signed value                    
   

Converting negative values:
      (3 digit) 10s complement code = 1000 abs(sign-mag code)

Example:   the (3 digit) 10s compl code for −34 is:   1000 − 34 = 966

Finding the sign-magnitude code for a (3 digit) 10s complement code
 

Question:   what's the signed values for the (3 digit) 10s compl codes 066 and 734 ?

Consider the mapping that we discussed previously:


   3 digit
   10s compl code      
   (odometer code)             
           500     996 997 998 999 000 001 002 003 004     499
            +---+...+---+---+---+---+---+---+---+---+...+---+    
                   •••• ••• ••    ( )  •   ••  ••• ••••
          -500     -4  -3  -2  -1   0   1   2   3   4      499
  Signed value                    
   

Notice that:
      Codes that starts with a digit 0,1,2,3,4 represents positive values (and ZERO)
      Codes that starts with a digit 5,6,7,8,9 represents negative values

Finding the sign-magnitude code for a (3 digit) 10s complement code
 

How to find the (positive) value of a (3 digit) 10s complement code that starts with 0,1,2,3 or 4:

Example:   066


   3 digit
   10s compl code      
   (odometer code)                                     066=??
           500     996 997 998 999 000 001 002 003 004     499
            +---+...+---+---+---+---+---+---+---+---+...+---+    
                   •••• ••• ••    ( )  •   ••  ••• ••••
          -500     -4  -3  -2  -1   0   1   2   3   4      499
  Signed value                    
   

Decoding a 10s compl code that starts with 0,1,2,3, or 4:
      Read the 10s complement code as a (positive) value - possibly ignoring the leading ZEROs.

Example:   the signed value represented by 066 is:   66

Finding the sign-magnitude code for a (3 digit) 10s complement code
 

How to find the (negative) value of a (3 digit) 10s complement code that starts with 5,6,7,8, or 9:

Example:   734


   3 digit
   10s compl code      
   (odometer code)   734=??        
           500     996 997 998 999 000 001 002 003 004     499
            +---+...+---+---+---+---+---+---+---+---+...+---+    
                   •••• ••• ••    ( )  •   ••  ••• ••••
          -500     -4  -3  -2  -1   0   1   2   3   4      499
  Signed value                    
   

Decoding a 10s compl code that starts with 5,6,7,8, or 9:
      (Signed) value = (1000 10s compl code)

Example:   the value represented by 734 is:   − (1000 − 734) = −266