Computer
Arithmetic
CP1-Lecture 3
Binary Addition
Binary Addition
• Performed in the same A B A+B
manner as in decimal 0 0 0
arithmetic 0 1 1
1 0 1
• Since 1 is the largest 1 1 0 plus a
digit in the binary carry 1
System, any sum greater
than 1 requires digit to
be carried over
Binary Addition
10101 = 21
• Two n-bit values
– Add individual bits + 11001 = + 25
– Propagate carries 101110 46
Binary Subtraction
Binary Subtraction
• Subtraction of a number from another can be
accomplished by adding the complement of the
subtrahend to the minuend.
• 1’s Complement
• 2’s Complement
Binary Subtraction
• 1s Complement Subtraction
- Subtraction of binary numbers using the 1’s complement
method allows subtraction only by addition.
• The 1’s complement of a binary number can be obtained
by changing all 1s to 0s and all 0s to 1s
1001001011
1’s complement = 0110110100
Binary Subtraction: 1’s
complement
• To subtract a smaller number from a larger number, the
1’s complement method is as follows:
- Remove the carry and add it to the result.
- This carry is called end-around-carry.
Example
110101 2 110101 2
- 100101 2 + 011010 2
1001111
001111
+ 1
010000 2
Answer: 10000 2
Example
101011 2 101011 2
- 111001 2 + 000110 2
110001 001110 2
Negative Value
Answer:-001110 2
Binary Subtraction: 1’s
complement
• Subtraction of a large number from a smaller one by the
1’s complement method.
- The answer is the 1’s complement of the result and is
opposite in sign. There is no carry
Binary Subtraction: 2’s
complement
• 2’s complement of a binary number can be obtained by
adding 1 to its 1’s complement.
• Subtraction of a smaller number from a larger one by the
2’s complement.
- Omit the carry (there is always a carry in this case)
Example
110110 2
- 010110 2 101001
+ 1 110110 2
101010 + 101010 2
1100000 2
DROP
Answer: 100000 2
Example
10110 2
- 11010 2 00101
+ 1 10110 2
00110 + 00110 2
11100 2
00011
+ 1
Answer: -00100 2 00100 2
Binary Multiplication
Binary Multiplication
• Follows the same general rules as multiplication in
decimal number system.
A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Example
1110
x 1011
1110
1110
0000
1110
10011010
Octal Addition
Example
11
6437
+ 2510
99
- 88
11147
Octal Subtraction
Example
8
00 8
11 147
8 9
- 6 437
2 510
Hexadecimal Addition
Example
11
7 C 3 9
+ 3 7 F 2
20 18 11
- 16 16
B 4 2 B
Hexadecimal
Subtraction
Example
B 16
7 C 3 9
19
- 3 7 F 2
4 4 4 7
“For the Lord gives wisdom; From His mouth come
knowledge and understanding.”
–Proverbs 2:6