Addition & Subtraction


Signed Integer Representation
We need to represent both positive and negative numbers. Three systems are used for representing such numbers:
*      Signed magnitude
*      1’s complement
*      2’s complement
Signed Magnitude
A signed-magnitude number has a sign as its left-most bit (also referred to as the high-order bit or the most significant bit) while the remaining bits represent the magnitude (or absolute value) of the numeric value.
 
Example 3.1:
In an 8-bit word, –1 would be represented as 10000001, and +1 as 00000001.
 
Here is the table of integer representation:



 
 
What is overflow?
v   Overflow can only occur when adding two numbers that have the same sign.
v  The carry-out signal from the sign-bit position is not a sufficient indicator of overflow when adding signed numbers.
 
Binary Addition
 
Arithmetic calculations on integers that are represented using this notation
(1) If the signs are the same, add the magnitudes and use that same sign for the result;
(2) If the signs differ, you must determine which operand has the larger magnitude. The sign of the result is the same as the sign of the operand with the larger magnitude, and the magnitude must be obtained by subtracting (not adding) the smaller one from the larger one.
 
 
 
 
Table 3.1 to represent addition of binary numbers.   
 
 
 
                                                                 
 
                                     Table 3.1
 
Example 3.2:
Question
Add 010011112 to 001000112 using signed-magnitude arithmetic
Answer:

If there is a carry here, we say that we have an overflow condition and the carry is discarded, resulting in an incorrect sum. There is no overflow in this example.
                                                              
In signed magnitude, the sign bit is used only for the sign, so we can't "carry into" it. If there is a carry emitting from the seventh bit, our result will be truncated as the seventh bit overflows, giving an incorrect sum.
 
Example 3.3:
Question
Add 010011112 to 011000112 using signed-magnitude arithmetic.

We obtain the erroneous result of 79 + 99 = 50.
 
 
Binary Subtraction
 
As with addition, signed-magnitude subtraction is carried out in a manner similar to pencil and paper decimal arithmetic, where it is sometimes necessary to borrow from digits in the minuend.
 
Example 3.4:
Question
Subtract 010011112 from 011000112 using signed-magnitude arithmetic
 
We find 011000112 – 010011112 = 000101002 in signed-magnitude representation.
 
If two numbers have different signs?
Example 3.5:
Question
Add 100100112 (–19) to 000011012 (+13) using signed-magnitude arithmetic.
 
 
Complement Representation of Numbers
 
*    The 1’s complement of a binary number can be obtained by changing all 1s to 0s and all 0s to 1s.
*    The 2’s complement of a binary number can be obtained by adding 1 to its 1’s complement.
 
Example 3.6:
1.                                                             2. Two’s complement addition
     Decimal value: 9                                         0000 0101 = +5       
    Binary value: 01001                                 + 1111 1101 = -3
    1’s complement: 10110                            _______________
    2’s complement: 10111                                0000 0010 = +2
Decimal value: -9                                       
 
3. Two’s complement subtraction
       0000 0111 = +7
+1111  0100 = -12
______________
   1111  1011 = -5
 
 
 
 
Hexadecimal Addition

 
 
Example 3.7:  (Use the color code in each step to see what’s happening)
 
The problem:
 
You are to add these numbers:
 
 
 
 
 
 
 
A
C
5
A
9
 
E
D
6
9
4
 
 
 
 
 
 
 
Carry Over:
 
 
 
 
 
 
1. Add one column at a time
2. Convert to decimal & add (9 + 4 = 13)
3. Follow less than 16 rule
            Decimal 13 is hexadecimal D
 
A
C
5
A
9
 
E
D
6
9
4
 
 
 
 
 
D
 
Carry Over:
 
 
 
1
 
 
1.         Add next column
2.         Convert to decimal & add (10 + 9 = 19)
3.         Follow 16 or larger than 16 rule
            (19 – 16 = 3 carry a 1)
 
A
C
5
A
9
 
E
D
6
9
4
 
 
 
 
3
D
 
Carry Over:
 
 
 
1
 
 
1.         Add next column
2.         Convert to decimal & add (1 + 5 + 6 = 12)
3.         Follow less than 16 rule, convert to hex
            Decimal 12 is hexadecimal C
 
A
C
5
A
9
 
E
D
6
9
4
 
 
 
C
3
D
 
 
Carry Over:
 
1
 
 
 
 
1.         Add next column
2.         Convert to decimal & add (12 + 13 = 25)
3.         Follow 16 or larger than 16 rule
            (25 – 16 = 9 carry a 1)
 
A
C
5
A
9
 
E
D
6
9
4
 
 
9
C
3
D
 
Carry Over:
 
1
 
 
 
 
 
1.         Add next column
2.         Convert and add (1 + 10 + 11 = 22)
3.         Follow 16 or larger than 16 rule
            (22 – 16 = 6 carry a 1)
 
 
A
C
5
A
9
 
 
B
D
6
9
4
 
 
6
9
C
3
D
 
Carry Over:
 
1
 
 
 
 
 
1.         Add next column
2.         Convert and add (1 + 0 + 0 = 1)
3.         Follow less than 16 rule
 
0
A
C
5
A
9
 
0
B
D
6
9
4
 
1
6
9
C
3
D
 
Hexadecimal Subtraction
 
Example 3.8:
 


 

0 comments:

Post a Comment

 
Copyright © ComPutEr???