You are on page 1of 21

Binary Operations

Math/Logical
Binary Math
Decimal Addition Example
1) Add 8 + 7 = 15
Add 3758 to 4657: Write down 5, carry 1

2) Add 5 + 5 + 1 = 11
111 Write down 1, carry 1
3758 3) Add 7 + 6 + 1 = 14
+ 4657 Write down 4, carry 1

8 415 4) Add 3 + 4 + 1 = 8
Write down 8
Decimal Addition Explanation
What just happened?
111
3758 1 1 1 (carry)
3 7 5 8
+ 4657 +4 6 5 7
8415 -
8 14 11 15 (sum)
10 10 10 (subtract the base)

8 4 1 5

So when the sum of a column is equal to or greater than


the base, we subtract the base from the sum, record the
difference, and carry one to the next column to the left.
Binary Addition Rules
Rules:
 0+0 =0
 0+1 =1
 1+0 =1 (just like in decimal)

 1+1 = 210 = 102 = 0


with 1 to carry
 1 + 1 + 1 = 310 = 112 =
1 with 1 to carry
Binary Addition Example 1
Col 1) Add 1 + 0 = 1
Example 1: Add Write 1
binary 110111 to 11100 Col 2) Add 1 + 0 = 1
Write 1
Col 3) Add 1 + 1 = 2 (10 in binary)
1 1 1 1 Write 0, carry 1
1 1 0 1 1 1 Col 4) Add 1+ 0 + 1 = 2
Write 0, carry 1
+ 0 1 1 1 0 0 Col 5) Add 1 + 1 + 1 = 3 (11 in binary)
Write 1, carry 1
1 0 1 0 0 1 1
Col 6) Add 1 + 1 + 0 = 2
Write 0, carry 1
Col 7) Bring down the carried 1
Write 1
Binary Addition Explanation
In the first two columns,
What is actually there were no carries.
happened when we In column 3, we add 1 + 1 = 2
carried in binary? Since 2 is equal to the base, subtract
the base from the sum and carry 1.
1 1 1 1 In column 4, we also subtract
the base from the sum and carry 1.
1 1 0 1 1 1
In column 5, we also subtract
+ 0 1 1 1 0 0 the base from the sum and carry 1.
2 3 2 2 In column 6, we also subtract
- 2 2 2 2 . the base from the sum and carry 1.
In column 7, we just bring down the
1 0 1 0 0 1 1 carried 1
Binary Addition Verification
You can always check your Verification
answer by converting the
figures to decimal, doing the 1101112  5510
addition, and comparing the +0111002 + 2810
answers.
8310

1 1 0 1 1 1 64 32 16 8 4 2 1
+ 0 1 1 1 0 0 1 0 1 0 0 1 1
1 0 1 0 0 1 1 = 64 + 16 + 2 +1
= 8310
Binary Addition Example 2
Example 2: Verification
Add 1111 to 111010. 1110102  5810
+0011112 + 1510
1 1 1 1 1 7310
1 1 1 0 1 0
+ 0 0 1 1 1 1 64 32 16 8 4 2 1
1 0 0 1 0 0 1
1 0 0 1 0 0 1
= 64 + 8 +1
= 7310
Decimal Subtraction
Example
Subtract 1) Try to subtract 5 – 7  can’t.
Must borrow 10 from next column.
4657 from 8025: Add the borrowed 10 to the original 5.
Then subtract 15 – 7 = 8.
2) Try to subtract 1 – 5  can’t.
7 9 11 Must borrow 10 from next column.
But next column is 0, so must go to
8 10 2 15 column after next to borrow.
- 4 6 5 7 Add the borrowed 10 to the original 0.
Now you can borrow 10 from this column.
3 3 6 8
Add the borrowed 10 to the original 1..
Then subract 11 – 5 = 6
3) Subtract 9 – 6 = 3
4) Subtract 7 – 4 = 3
Decimal Subtraction
Explanation
8 0 2 5
- 4 6 5 7
3 3 6 8
 So when you cannot subtract, you borrow from the
column to the left.
 The amount borrowed is 1 base unit, which in
decimal is 10.
 The 10 is added to the original column value, so
you will be able to subtract.
Binary Subtraction
Explanation
 In binary, the base unit is 2

 So when you cannot subtract, you borrow from the


column to the left.
 The amount borrowed is 2.
 The 2 is added to the original column value, so
you will be able to subtract.
Binary Subtraction
Example 1
Col 1) Subtract 1 – 0 = 1
Example 1: Subtract Col 2) Subtract 1 – 0 = 1
binary 11100 from 110011Col 3) Try to subtract 0 – 1  can’t.
Must borrow 2 from next column.
But next column is 0, so must go to
column after next to borrow.
2 1 Add the borrowed 2 to the 0 on the right.
0 0 2 2 Now you can borrow from this column
(leaving 1 remaining).
1 1 0 0 1 1 Add the borrowed 2 to the original 0.
Then subtract 2 – 1 = 1
- 1 1 1 0 0 Col 4) Subtract 1 – 1 = 0
Col 5) Try to subtract 0 – 1  can’t.
1 0 1 1 1 Must borrow from next column.
Add the borrowed 2 to the remaining 0.
Then subtract 2 – 1 = 1
Col 6) Remaining leading 0 can be ignored.
Binary Subtraction
Verification
Subtract binary
Verification
11100 from 110011: 1100112  5110

2 1 - 111002 - 2810
0 0 2 2 2310
1 1 0 0 1 1
- 1 1 1 0 0 64 32 16 8 4 2 1
1 0 1 1 1
1 0 1 1 1
= 16 + 4 + 2 + 1
= 2310
Binary Subtraction
Explanation
 In binary, the base unit is 2

 So when you cannot subtract, you borrow from the


column to the left.
 The amount borrowed is 2.
 The 2 is added to the original column value, so
you will be able to subtract.
Binary Subtraction
Example 1
Col 1) Subtract 1 – 0 = 1
Example 1: Subtract Col 2) Subtract 1 – 0 = 1
binary 11100 from 110011Col 3) Try to subtract 0 – 1  can’t.
Must borrow 2 from next column.
But next column is 0, so must go to
column after next to borrow.
2 1 Add the borrowed 2 to the 0 on the right.
0 0 2 2 Now you can borrow from this column
(leaving 1 remaining).
1 1 0 0 1 1 Add the borrowed 2 to the original 0.
Then subtract 2 – 1 = 1
- 1 1 1 0 0 Col 4) Subtract 1 – 1 = 0
Col 5) Try to subtract 0 – 1  can’t.
1 0 1 1 1 Must borrow from next column.
Add the borrowed 2 to the remaining 0.
Then subtract 2 – 1 = 1
Col 6) Remaining leading 0 can be ignored.
Binary Subtraction
Verification
Subtract binary
Verification
11100 from 110011: 1100112  5110

2 1 - 111002 - 2810
0 0 2 2 2310
1 1 0 0 1 1
- 1 1 1 0 0 64 32 16 8 4 2 1
1 0 1 1 1
1 0 1 1 1
= 16 + 4 + 2 + 1
= 2310
Binary Subtraction
Example 2
Verification
Example 2: Subtract
binary 10100 from 101001 1010012  4110
- 101002 - 2010
2110
0 2 0 2
1 0 1 0 0 1 64 32 16 8 4 2 1
- 1 0 1 0 0 1 0 1 0 1
1 0 1 0 1 = 16 + 4 + 1
= 2110
Binary Multiplication
1 0 1 1 1
x 1 0 1 0
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1

1 1 1 0 0 1 1 0
19 / 45
Complements
 1’s Complement (Diminished Radix Complement)
 All ‘0’s become ‘1’s
 All ‘1’s become ‘0’s

Example (10110000)2
 (01001111)2
If you add a number and its 1’s complement …

10110000
+ 010011
11111111
Complements
 2’s Complement (Radix Complement)
 Take 1’s complement then add 1
 Toggle all bits to the left of the first ‘1’ from the right
OR
Example:
Number:
1’s Comp.:
10110000
01001111
+ 1

01010000

You might also like