(M4S2-SUPPLEMENTARY2) Addition and Subtraction in Number Systems
(M4S2-SUPPLEMENTARY2) Addition and Subtraction in Number Systems
1
Rules: Examples: 1 111 1
0+0=0 110112
11 1 1
0+1=1 110112 101012
1+0=1 + 10012 + 10012
1 + 1 = 10 (which 1001002 1110012
is 0 carry 1)
Now that we know binary numbers, we will learn how to add them. Binary addition is
much like your normal everyday addition (decimal addition), except that it carries on
a value of 2 instead of a value of 10. Looking at the basics of binary addition, 0 + 0 is
obviously 0, 0 + 1 is equal to 1, 1 + 0 is of course equal to 1, and 1 + 1 is 10, but since
10 is a double-digit binary number, 0 becomes part of the sum, and 1 gets carried
over.
For example: in decimal addition, if you add 8 + 2 you get ten, which you write as 10;
in the sum this gives a digit 0 and a carry of 1. Something similar happens in binary
addition when you add 1 and 1; the result is two (as always), but since two is written
as 10 in binary, we get, after summing 1 + 1 in binary, a digit 0 and a carry of 1.
Let’s try to add the binary numbers 11011 and 1001. We add 1 + 1, so we put 0 as
part of the sum then carry over 1. Next we add 1 and the 1 we carried over, so again,
it is 0 and carry over 1. Next is 1 + 0 + 0 so we just write 1 in the sum. Then 1 + 1 so 0
goes to the sum and 1 will be carried over. Then 1 + 1 again, so 0 carry over 1. Since
there is nothing else to add, we bring down 1. So 11011 + 1001 is equal to 100100
base 2. Just a reminder, do not forget to write the base.
Another example, 11011 + 10101 + 1001. First, 1 + 1 + 1, the sum is 3 and 3 in binary
2
is 11 therefore we put 1 as part of the sum and the other 1 as a carry over. Next is 1 +
1 + 0 + 0 so it will be 0 in the sum and 1 in the carry over. Then 1 + 0 + 1 + 0, so again
put 0 in the sum then carry over 1. Next is 1 + 1 + 0 + 1 which is 3, that is equivalent
to 11 binary so we write 1 in the sum and 1 in the carry over. Next is 1 + 1 + 1, which
basically the same with the previous one so we write in the sum and in the carry over.
Since there is nothing left to add we bring down 1. Therefore, 11011 + 10101 + 1001
is equal to 111001 base 2.
2
Rules: Example:
0-0=0 2
002
0 - 1 = 1 (borrow 2) 110112
1-0=1 - 11012
1-1=0 11102
1 14
24
- 8
16
Let us subtract 1101 from 11011. First we do 1 – 1 we get 0, then 1 – 0 and we get 1.
Next is 0 – 1, so we need to borrow from the higher significant digit, so 0 becomes 2
and 1, where we borrowed becomes 0, note that 2 must be written as 10 but we will
be writing it as 2 so that it will be easier to understand the logic,. Now we can
subtract 2 – 1 which will give 1. Next is another 0 -1 so we will borrow from 1, 0
becomes 2 so we can now subtract 1 from 2 to give 1, since 1 is now zero, we stop.
So 11011 – 1101 is equal to 1110 base 2.
3
The are other ways to subtract Binary Number:
• 1's complement
• Done by inverting the binary digits (e.g. 1 becomes 0, 0
becomes 1) in the subtrahend.
• 2's complement
• Done by finding the 1’s complement of a binary number in the
subtrahend then add 1.
• Generally used because it will only have one representation of a
value 0 compare to 1’s complement.
Subtraction of binary numbers can also be done using complement. The two types of
complement is the 1’s complement and the 2’s complement. 1’s complement is done
by inverting the binary digits, which means 0 will be written as 1 and 1 as 0. On the
other hand, 2’s complement is done by getting the 1’s complement of the binary
number then add 1. In data representation, 2’s complement is generally used because
it only uses 1 representation for the value 0, while 1’s complement can give a
negative 0. We will not be emphasizing on that, though.
4
1's complement 2's complement
111001012 111001012
000110102 000110102
+ 12
000110112
To do 1’s complement, all we have to do is to invert every binary digit or bit. To get
the 1’s complement of 1110101 we need to change all 0’s to 1, and all 1’s to 0.
Therefore, the 1’s complement of 11100101 is 00011010. To get the 2’s complement,
we take the 1’s complement of the number then add 1.
5
Steps:
Using 1's complement 1. Find the 1’s complement
of the subtrahend.
1 1 11 The final carry 2. Change the subtraction
11011012 11011012 will be added to
operation to addition.
get the correct
- 110012 + 1100110 2 difference of
3. Solve for the sum of the
1 1 binary numbers.
The subtraction 10100112 the two binary
numbers. 4. Add the final carry to the
operator becomes
addition + 12 computed sum to get the
correct difference.
10101002
You must make sure
that the number of
digits in the
subtrahend and
minuend are the same.
To subtract binary numbers using 1’s complement, we have to get the 1’s
complement of the subtrahend. So if we subtract 11001 from 1101101, the first step
is to invert the subtrahend, in this case 11001, but before we can do that, we have to
make sure that the number of digits in the minuend and the subtrahend are the
same. Since 1101101 has 7 digits and 11001 has only five, we need to append two
zeros to the left of the subtrahend to make it 7 digits. Since the subtrahend and the
minuend both have 7 digits we can now get the complement of the subtrahend. The
subtrahend is now 0011001 so its complement is 1100110. Next is to change the
operation from subtraction to addition, this means that the expression is now
1101101 + 1100110. (explain the addition part, adding that the last carry must be
added).
6
Steps:
Using 2's complement 1. Find the 2’s complement of the
The final carry
subtrahend.
is discarded. 1 1 11 11
2. Change the subtraction
11011012 11011012 operation to addition.
- 110012 + 11001112 3. Solve for the sum of the binary
numbers.
The subtraction 10101002 4. Discard the final (excess) carry.
operator becomes
addition
**The computed sum of the
original minuend and the 2’s
You must make sure
complement of the subtrahend
that the number of
digits in the minuend
is the difference.
and subtrahend are the
same.
To use the 2’s complement, we get the 2’s complement of the subtrahend first. Just
remember that the number of digits of the minuend and the subtrahend must be the
same. (Explain how to come up with the 2’s complement, perform addition, the final
carry is discarded).
7
Adding octal numbers are just like adding decimal
numbers. But when the sum is greater than 7, you must
make sure that you convert it to octal number first.
Addition of Octal numbers follow the same rules as addition. But after 7, the next
value is 10, therefore, if the sum is greater than 7 there will be a carry over. For
example, if we add 6 + 3 in octal, we add it as how we do it in decimal, so 6 + 4 is 9.
Since 10 is greater than 7 we have to convert it first to its octal equivalent. SO 10 / 8
is 1 remainder 2. So 2 will stay as part of the sum and 1 will be carried over. Let’s look
a more detailed example.
8
Examples:
111
4 + 6 = 10, since 10 is greater
5438 7448 than 7, we have to
+ 148 + 568 convert it to its octal
equivalent
5578 10228
10 ÷ 8 = 1 remainder 2, the
remainder will be
written as part of the
sum and the quotient
will be carried over
First example is to add 543 base 8 14 base 8. So 3+4 is 7, 4+1 is 5, the bring down 5.
There are no carry overs in this example because there is no sum that is greater than
7.
For the second example we will add 744 base 8 and 56 base 8. First is 4+6, we add it
as how we do it in decimal so we will get 10, since 10 is greater than 7 we convert it
to decimal. So we do 10/8 which will give 1 remainder 2, 2 becomes part of the sum
and 1 is carried over. Next we have 1+4+5, which is again 10, 10 is greater than 7 so
we get is octal equivalent, 10/8 is 1 remainder 2, 2 goes to the sum and 1 is carried
over. Next is 1+7, we get 8, 8 is greater than 7 so, again, we convert it to octal. 8/8 is
1 remainder 0. 0 goes as part of the sum, 1 is carried over. Since there is no more to
add to 1, we bring it down. So, the sum of 744 base 8 and 56 base 8 is 1022 base 8.
9
Subtraction of Octal numbers also follow how
subtraction of Decimal numbers is, but instead of
borrowing 10, you must borrow 8 from the next higher
significant digit.
Just like addition, subtraction of octal numbers follows the rules of decimal
subtraction. But since octal numbers use 8 as base, borrowing means we borrow 8
from the higher significant digit. Let’s see an example.
10
Borrowed 8 from 5 Borrowed 8 from 2,
8+3=11
48 5 8 1 11
50258 60238
- 1128 - 41158
47138 17068
First example, subtract 112 base 8 from 5025 base 8. First is 5-3, we get 3. Next is 2-1,
we get 1. Then 0-1, since there is still a higher significant digit, we will borrow, so we
borrow 8 from 5. so 0 becomes 8, and 5 will be reduced by 1 and becomes 4. Now we
can subtract 8-1 and we get 7, then bring down 4. Subtracting 112 base 8 from 5025
base 8 will give us a difference of 4713 base 8.
Second example, subtract 4115 base 8 from 6023 base 8. We start with 3-5, we need
to borrow from 2 so 2 becomes 1 and 3 becomes 11, why? Because we borrowed 8
and add it to 3. We can now subtract 5 from 11, we get 6. Nest is 1-1 which gives 0,
then 0-1. We will borrow 8 from 6, 6 becomes 5 and 0 becomes 8. Now we subtract,
8-1 is 7. Last, 5-4 is 1. So, 6023 base 8 minus 4115 base 8 is equal to 1706 base 8.
11
Addition and subtraction of Hexadecimal Numbers are
just like how we did with Octal Numbers, the same rules
in carrying and borrowing is applied, but note that the
base of Hexadecimal Numbers is 16.
You have already learned how to add and subtract binary and octal number systems.
Basically, the rules or steps that you have learned in the previous also applies . Just
remember that the base of hexadecimal number system is 16 and that the highest
single digit is F which is equivalent to 15 in decimal.
12
1 Note that A = 10,
7 9 B 2 16 2 + 10 = 12,
+ 3 1 9 A 16
In Hexadecimal, 12 is C
A B 4 C 16 B = 11,
11 + 9 = 20, 20 is greater than
15 so we need to
convert it to
Hexadecimal
20 ÷ 16 = 1 remainder 4, 4
becomes part of the
sum and 1 is carried.
As an example, we add 79B2 bas 16 and 319A base 16. First we add 2 and A, note
that A is equal to 10 so 10+2 is 12, 12 in hexadecimal is C so we write C. Next is B+9,
B is 11 in decimal so we add 11+9 to get 20. Now 20 is greater than 15, the largest
single digit possible in hexadecimal so we need to convert 20 to hexadecimal. 20/16
is 1 remainder 4, 4 will be written as part of the sum and 1 as a carry over. Next is
1+9+1 which is equal to 11, 11 in hexadecimal is B, so we put B. Last is 7+3, it will give
us 10, 10 is A in hexadecimal so we write A. 79B2 base 16 + 319A base 16 equals
AB4C base 16.
13
Borrow 16 from 8 Borrow 16 from 1,
16 16 + 3 = 19
7 0 19
8 1 3 F16 Note that F = 15,
- 4 B 216 15 - 2 = 13,
in Hexadecimal, 13 is D
7 C 8 D16
We now look at how subtraction is done in hexadecimal. Subtract 4B2 base 16 from
813F base 16. First, F-2, note that F is 15 in decimal so 15-2 equals 13, in decimal it is
D. Next 3-B, B is 11 in decimal so we cannot do 3-11, we need to borrow. We borrow
16, the base of hexadecimal number, from 1, so 1 will be reduced by 1 and will
become 0, the 16 that we borrowed will be added to 3 which will become 19. So we
can now do 19-11 which is equal to 8. next will be 0-4, we need to borrow from 8, 8
becomes 7 and 0 becomes 16. 16-4 is 12 which C in hexadecimal so we write C. Then
bring down 7. Therefore, 813F base 16 – 4B2 base 16 is equal to 7C8D base 16.
14