Beruflich Dokumente
Kultur Dokumente
Dr Supriya Raheja
Addition
• Signed numbers
• Unsigned numbers
Dr Supriya Raheja
Adding Unsigned Numbers
• Addition is done exactly like adding decimal numbers,
except that you have only two digits (0 and 1).
• The only number facts to remember are that
Dr Supriya Raheja
Examples:
• Add the numbers 06 =0110 and
10 2
07 =0111 (answer=13 =1101 )
10 2 10 2
Dr Supriya Raheja
Contd…
• Consider 13+5
• The result is a 5 bit number. So the carry bit from adding the
two most significant bits represents a results
that overflows (because the sum is too big to be represented
with the same number of bits as the two addends).
Dr Supriya Raheja
Examples:
10101 and 11011
11001 and 111
Dr Supriya Raheja
Examples: floating point numbers
10101.101 and 1101.011 111.0111 and 10011.001
Dr Supriya Raheja
Adding signed numbers
• Adding signed numbers is not significantly different from
adding unsigned numbers. Recall that signed 4 bit numbers
(2's complement) can represent numbers between -8 and 7.
Dr Supriya Raheja
Examples:
Dr Supriya Raheja
Binary Subtraction
1001 – 10 = 111:
1001
10
1 11
Dr Supriya Raheja
Examples
1010101.10 from 1111011.11
11010.101 from 101100.011
Dr Supriya Raheja
Exercise
• 100010110 − 1111010 = 10011100
• 101101 − 100111 = 110
• 1110110 − 1010111 = 11111
Dr Supriya Raheja
Subtraction using 2’s complement
• The operation is carried out by means of the following
steps:
(i) At first, 2’s complement of the subtrahend is found.
(ii) Then it is added to the minuend.
(iii) If the final carry over of the sum is 1, it is dropped, and the
result is positive.
(iv) If there is no carry over, the two’s complement of the sum will
be the result and it is negative.
Dr Supriya Raheja
Example 1
(i) 110110 - 10110
Solution:
• The numbers of bits in the subtrahend is 5 while that of minuend is 6. We make the
number of bits in the subtrahend equal to that of minuend by taking a `0’ in the
sixth place of the subtrahend.
• Now, 2’s complement of 010110 is (101101 + 1) i.e.101010. Adding this with the
minuend.
•
1 1 0 1 1 0 Minuend
1 0 1 0 1 0 2’s complement of subtrahend
Carry over 1 1 0 0 0 0 0 Result of addition
• After dropping the carry over we get the result of subtraction to be 100000.
Dr Supriya Raheja
Example 2
(ii) 10110 – 11010
Solution:
• 2’s complement of 11010 is (00101 + 1) i.e. 00110. Hence
•
Minued - 1 0 1 1 0
2’s complement of subtrahend - 0 0 1 1 0
Result of addition - 1 1 1 0 0
Dr Supriya Raheja
Subtraction using 1’s complement
• The steps to be followed in subtraction by 1’s
complement are:
i) To write down 1’s complement of the subtrahend.
ii) To add this with the minuend.
iii) If the result of addition has a carry over then it is dropped and
an 1 is added in the last bit.
iv) If there is no carry over, then 1’s complement of the result of
addition is obtained to get the final result and it is negative.
Dr Supriya Raheja
Examples
110101 – 100101 101011 – 111001
Dr Supriya Raheja
Examples: floating point
1011.001 – 110.10 10110.01 – 11010.10
Dr Supriya Raheja
Exercise
• 1. 101 + 11 =
2. 111 + 111 =
3. 1010 + 1010 =
4. 11101 + 1010 =
5. 11111 + 11111 =
• 6. 110 - 10 =
7. 101 - 11 =
8. 1001 - 11 =
9. 1101 - 11 =
10. 10001 - 100 = Dr Supriya Raheja
Exercise
Dr Supriya Raheja
Exercise
Solve the following equations, where all numbers, including x, are binary:
(a)
x + 11 = 1101 x =
(b) x – 10 = 101 x =
(c) x – 1101 = 11011 x =
(d) x + 1110 = 10001 x =
(e) x + 111 = 11110 x =
(f) x – 1001 = 11101 x =
Dr Supriya Raheja