In: Computer Science
a)
Adding 110110 and 111000 in binary
110110
111000
-----------
(1)101110
-----------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 101110
Verification
---------------
first = 110110
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.
110110 is flipped to 001001
II. Add 1 to above result
001001 + 1 = 001010
III. Now convert this result to decimal value
Converting 1010 to decimal
1010
=> 1x2^3+0x2^2+1x2^1+0x2^0
=> 1x8+0x4+1x2+0x1
=> 8+0+2+0
=> 10
Answer: -10
second = 111000
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.
111000 is flipped to 000111
II. Add 1 to above result
000111 + 1 = 001000
III. Now convert this result to decimal value
Converting 1000 to decimal
1000
=> 1x2^3+0x2^2+0x2^1+0x2^0
=> 1x8+0x4+0x2+0x1
=> 8+0+0+0
=> 8
Answer: -8
sum = 101110
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.
101110 is flipped to 010001
II. Add 1 to above result
010001 + 1 = 010010
III. Now convert this result to decimal value
Converting 10010 to decimal
10010
=> 1x2^4+0x2^3+0x2^2+1x2^1+0x2^0
=> 1x16+0x8+0x4+1x2+0x1
=> 16+0+0+2+0
=> 18
Answer: -18
This is correct since we can verify that -10+-8 = -18
So, there was no overflow.
b)
001100-011100 = 001100+(-011100)
let's first convert -011100 to two's complement positive.
convert -011100 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
011100 is flipped to 100011
Step 2:. Add 1 to above result
100011 + 1 = 100100
Adding 001100 and 100100 in binary
001100
100100
-----------
(0)110000
-----------
Sum does not produces a carry
So, sum of these numbers in binary is 110000
Verification
---------------
first = 001100
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 1100 to decimal
1100
=> 1x2^3+1x2^2+0x2^1+0x2^0
=> 1x8+1x4+0x2+0x1
=> 8+4+0+0
=> 12
Answer: 12
second = 100100
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.
100100 is flipped to 011011
II. Add 1 to above result
011011 + 1 = 011100
III. Now convert this result to decimal value
Converting 11100 to decimal
11100
=> 1x2^4+1x2^3+1x2^2+0x2^1+0x2^0
=> 1x16+1x8+1x4+0x2+0x1
=> 16+8+4+0+0
=> 28
Answer: -28
sum = 110000
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.
110000 is flipped to 001111
II. Add 1 to above result
001111 + 1 = 010000
III. Now convert this result to decimal value
Converting 10000 to decimal
10000
=> 1x2^4+0x2^3+0x2^2+0x2^1+0x2^0
=> 1x16+0x8+0x4+0x2+0x1
=> 16+0+0+0+0
=> 16
Answer: -16
This is correct since we can verify that 12+-28 = -16
So, there was no overflow.