In: Computer Science
For the following operations: write the operands as 2's
complement binary numbers then perform the addition or subtraction
operation shown. Show all work in binary operating on 8-bit
numbers.
7 + 3
7 - 3
3 - 7
1)
Number: 7
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into
binary
Divide 7 successively by 2 until the quotient is 0
> 7/2 = 3, remainder is 1
> 3/2 = 1, remainder is 1
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 111
So, 7 of decimal is 111 in binary
Adding 5 zeros on left hand side of this number to make this of
length 8
so, 7 in 2's complement binary is 00000111
Number: 3
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into
binary
Divide 3 successively by 2 until the quotient is 0
> 3/2 = 1, remainder is 1
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 11
So, 3 of decimal is 11 in binary
Adding 6 zeros on left hand side of this number to make this of
length 8
so, 3 in 2's complement binary is 00000011
Adding 00000111 and 00000011 in binary
00000111
00000011
-------------
(0)00001010
-------------
Sum does not produces a carry
So, sum of these numbers in binary is 00001010
Verification:
---------------
sum = 00001010
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=> 1010
=> 1x2^3+0x2^2+1x2^1+0x2^0
=> 1x8+0x4+1x2+0x1
=> 8+0+2+0
=> 10
Answer: 10
This is correct since we can verify that 7+3 = 10
So, there was no overflow.
2)
Number: 7
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into
binary
Divide 7 successively by 2 until the quotient is 0
> 7/2 = 3, remainder is 1
> 3/2 = 1, remainder is 1
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 111
So, 7 of decimal is 111 in binary
Adding 5 zeros on left hand side of this number to make this of
length 8
so, 7 in 2's complement binary is 00000111
Number: -3
Let's convert this to two's complement binary
This is negative. so, follow these steps to convert this into a 2's
complement binary
Step 1:
Divide 3 successively by 2 until the quotient is 0
> 3/2 = 1, remainder is 1
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 11
So, 3 of decimal is 11 in binary
Adding 6 zeros on left hand side of this number to make this of
length 8
So, 3 in normal binary is 00000011
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to
0.
00000011 is flipped to 11111100
Step 3:. Add 1 to above result
11111100 + 1 = 11111101
so, -3 in 2's complement binary is 11111101
Adding 00000111 and 11111101 in binary
00000111
11111101
-------------
(1)00000100
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 00000100
Verification:
---------------
sum = 00000100
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=> 100
=> 1x2^2+0x2^1+0x2^0
=> 1x4+0x2+0x1
=> 4+0+0
=> 4
Answer: 4
This is correct since we can verify that 7+-3 = 4
So, there was no overflow.
3)
Number: 3
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into
binary
Divide 3 successively by 2 until the quotient is 0
> 3/2 = 1, remainder is 1
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 11
So, 3 of decimal is 11 in binary
Adding 6 zeros on left hand side of this number to make this of
length 8
so, 3 in 2's complement binary is 00000011
Number: -7
Let's convert this to two's complement binary
This is negative. so, follow these steps to convert this into a 2's
complement binary
Step 1:
Divide 7 successively by 2 until the quotient is 0
> 7/2 = 3, remainder is 1
> 3/2 = 1, remainder is 1
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 111
So, 7 of decimal is 111 in binary
Adding 5 zeros on left hand side of this number to make this of
length 8
So, 7 in normal binary is 00000111
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to
0.
00000111 is flipped to 11111000
Step 3:. Add 1 to above result
11111000 + 1 = 11111001
so, -7 in 2's complement binary is 11111001
Adding 00000011 and 11111001 in binary
00000011
11111001
-------------
(0)11111100
-------------
Sum does not produces a carry
So, sum of these numbers in binary is 11111100
Verification:
---------------
sum = 11111100
since left most bit is 1, this number is negative number.
so, follow these steps below to convert this into a decimal
value.
I. first flip all the bits. Flip all 0's to 1 and all 1's to
0.
11111100 is flipped to 00000011
II. Add 1 to above result
00000011 + 1 = 00000100
III. Now convert this result to decimal value
=> 100
=> 1x2^2+0x2^1+0x2^0
=> 1x4+0x2+0x1
=> 4+0+0
=> 4
Answer: -4
This is correct since we can verify that 3+-7 = -4
So, there was no overflow.