Presentation is loading. Please wait.

Presentation is loading. Please wait.

Addition and Substraction

Similar presentations


Presentation on theme: "Addition and Substraction"— Presentation transcript:

1 Addition and Substraction
Binary 3 Addition and Substraction

2 Binary Addition Binary addition follows the same rules as decimal addition Put the two numbers you want to add one above the other Add them up column by column, and bring any carry’s to the following column (Once you have calculated your result – check your result again the decimal result)

3 Binary Addition 01101 + 01110 -------------
NOTE: 0 + 0 = 0 0 + 1 = 1 1 + 1 = 0 + carry of 1 = 1 + carry of 1 01101 Convert each number to decimal and see if your calculation was correct

4 Binary Addition Complete the following additions 01001 01100
01100

5 Binary Addition Complete the following additions 01001 01100
11000 01100 11010

6 Binary Subtraction To subtract any number, you can always add its opposite. to subtract a positive number, take the two’s complement of the number you want to subtract, and add that number instead E.g. 6 – 4 becomes 6 + (-4)

7 Binary Subtraction To subtract…
convert the numbers to binary using two’s complement representation. remember to take the two’s complement of any negative number, or any positive number to be subtracted add the numbers and interpret the result If the left most bit is a 1, the number is negative and we take the two’s complement to determine its value

8 Binary Subtraction 5  0000 0101 3  3 = 0000 0011 so -3 = 1111 1101
5  3  3 = so -3 = Add together: Ignore the carry out, and the result is positive 2

9 Binary Subtraction 3  0000 0011 5  5 = 0000 0101 -5 = 1111 1011
3  5  5 = = Add together: The left most bit indicates it’s negative, so take the two’s complement, answer is -2

10 Binary addition & subtraction
Complete the following exercises (convert to two’s complement binary representation before completing the addition. Interpret your two’s complement result) 11 – – 22 8 – – 5

11 Carry Out and Overflow What happens if we add 5+7 in 4-bit two’s complement? 5  0101 7  Because the most significant bit is a 1, we have to interpret this as a negative number, 1100  -4 !!!

12 Carry Out and Overflow How can we tell if an “overflow” has occurred?
If the sum of two positive numbers yields a negative result (e.g. 5+7 = -4), the sum has overflowed. If the sum of two negative numbers yields a positive result, the sum has overflowed. Otherwise, the sum has not overflowed. Why?

13 Carry Out and Overflow It is important to note the overflow and carry out can each occur without the other. In unsigned numbers, carry out is equivalent to overflow. In two's complement, carry out tells you nothing about overflow.

14 Addition Marble Adding


Download ppt "Addition and Substraction"

Similar presentations


Ads by Google