w4 Binary Operations
w4 Binary Operations
• Addition
• Subtraction
• Multiplication
• Division
• Addition
• Binary Addition
• It involves adding two binary numbers A B Addition
• 1’s complement
• Procedure
• Invert the binary number i.e. invert all the bits individually
• Where there is 1 change it to 0 and vice versa
• 2’s complement 1’s Compliment
Example: 1 0 1 1 02 01001
• Procedure
• First obtain 1’s complement
• Add a 1 to the Least Significant Bit
• Example: 10110010 0 1 0 0 1 1 0 1 1’s Compliment
+ 1
1 0 0 1 1 1 0 2’s Compliment
IST 2010 COP: Chapter 3: Binary Operations: Omae M. Oteri
2nd method
• Procedure
• Take the binary and check for the first 1 from the LSB
• Arrange the binary bits the way they appear including the first bit
Example 1: 1 0 1 1 0 0 1 0
• Complement the rest 0 1 0 0 1 1 1 0 2’s Compliment
• Compliment the subtrahend and add it to the minuend 1’s compliment for B = 0 1 1 1 0 0
A= 101101+
• If there is a carry take it round and add it to the LSB B’ = 0 1 1 1 0 0
1 0 0 1 0 0 1 + Result is a POSITIVE so add it
• The result will be correct and positive 001010
1
A’ = 010010+
B= 100011
0 1 1 0 1 1 1 + Result is a NEGATIVE so re-compliment
001000
IST 2010 COP: Chapter 3: Binary Operations: Omae M. Oteri
Subtraction using 2’s Complement
• Procedure
• Obtain the 2’s complement of the subtrahend
• Add it to the minuend
• If there is a carry discard it; the result is correct and positive
• If there is no carry; the result is negative and incorrect
• Re-complement it (using 2’s complement) and attaché a negative
Example 1:
A= 101101
B= 100011
B’ + 1 = 111101+
A = 101101
1 0 0 1 0 1 0 Discard the carry 1
Example 2:
B= 100011
A= 101101
A’ + 1 = 010011+
B = 100011
0 1 1 0 1 1 0 Result is a NEGATIVE so re-complement
001001
IST 2010 COP: Chapter 3: Binary Operations: Omae M. Oteri
Multiplication
• Example 1: Multiplying a single bit
A 1 1 0 1. 1 0 1
A B Result B 1 0 1 1. 1 1
0 0 0 1011 01
0 1 0 1011 01
1 0 0 1011 01
000000
1 1 1
1011 01
1 0 1 0 0 0 0 0. 0 0 0 1 1