In: Computer Science
Evaluate the following expressions, where two’s complement numbers, A is 11111110 and B is 00000010 and indicate the results. a. A + B b. A – B c. B–A d. –B e. – (-A)
A = 11111110
B = 00000010
A = 11111110
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.
   11111110 is flipped to 00000001
II. Add 1 to above result
00000001 + 1 = 00000010
III. Now convert this result to decimal value
Converting 10 to decimal
10
=> 1x2^1+0x2^0
=> 1x2+0x1
=> 2+0
=> 2
Answer: -2
B = 00000010
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 10 to decimal
10
=> 1x2^1+0x2^0
=> 1x2+0x1
=> 2+0
=> 2
Answer: 2
a)
A + B
Adding 11111110 and 00000010 in binary
    11111110
    00000010
-------------
 (1)00000000
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 00000000
00000000 in decimal is 0
Answer: 0
b)
A – B
convert -00000010 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00000010 is flipped to 11111101
Step 2:. Add 1 to above result
11111101 + 1 = 11111110
Adding 11111110 and 11111110 in binary
    11111110
    11111110
-------------
 (1)11111100
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 11111100
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
Converting 100 to decimal
100
=> 1x2^2+0x2^1+0x2^0
=> 1x4+0x2+0x1
=> 4+0+0
=> 4
Answer: -4
c. B–A
convert -11111110 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   11111110 is flipped to 00000001
Step 2:. Add 1 to above result
00000001 + 1 = 00000010
Adding 00000010 and 00000010 in binary
    00000010
    00000010
-------------
 (0)00000100
-------------
Sum does not produces a 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
Converting 100 to decimal
100
=> 1x2^2+0x2^1+0x2^0
=> 1x4+0x2+0x1
=> 4+0+0
=> 4
Answer: 4
d)
-B
convert -00000010 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00000010 is flipped to 11111101
Step 2:. Add 1 to above result
11111101 + 1 = 11111110
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.
   11111110 is flipped to 00000001
II. Add 1 to above result
00000001 + 1 = 00000010
III. Now convert this result to decimal value
Converting 10 to decimal
10
=> 1x2^1+0x2^0
=> 1x2+0x1
=> 2+0
=> 2
Answer: -2
e)  -(-A)
A = 11111110 
-A = -11111110 
convert -11111110 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   11111110 is flipped to 00000001
Step 2:. Add 1 to above result
00000001 + 1 = 00000010
-A = 00000010
-(-A) = -00000010
convert -00000010 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00000010 is flipped to 11111101
Step 2:. Add 1 to above result
11111101 + 1 = 11111110
so, -(-A) = 11111110
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.
   11111110 is flipped to 00000001
II. Add 1 to above result
00000001 + 1 = 00000010
III. Now convert this result to decimal value
Converting 10 to decimal
10
=> 1x2^1+0x2^0
=> 1x2+0x1
=> 2+0
=> 2
Answer: -2