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 ???
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 ! |
Important fact:
|
Example overflow:
250 (positive 250) + 400 (positive 400) ----- 650 ---> represents negative 350 positive 250 + positive 400 = positive 650 ≠ negative 350 !! |
Solving/preventing the overflow problem: use a longer 10s compl code
|
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)