In: Computer Science
(a) Convert the decimal numbers, 70 and -26 to binary in the signed 2’s complement system. Make sure there are enough digits in the results to be able to perform arithmetic operations with these two numbers.
(b) Perform in the signed 2’s complement system, (+70) + (-26)
(c) Perform in the signed 2’s complement system, (-70) - (-26)
(d) Perform in the signed 2’s complement system, (+70) + (+26)
a)
70
Since this is a positive number. we can directly convert this into binary
Divide 70 successively by 2 until the quotient is 0
> 70/2 = 35, remainder is 0
> 35/2 = 17, remainder is 1
> 17/2 = 8, remainder is 1
> 8/2 = 4, remainder is 0
> 4/2 = 2, remainder is 0
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1000110
So, 70 of decimal is 1000110 in binary
so, 70 in 2's complement binary is 01000110
-26
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 26 successively by 2 until the quotient is 0
> 26/2 = 13, remainder is 0
> 13/2 = 6, remainder is 1
> 6/2 = 3, remainder is 0
> 3/2 = 1, remainder is 1
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 11010
So, 26 of decimal is 11010 in binary
So, 26 in normal binary is 00011010
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
00011010 is flipped to 11100101
Step 3:. Add 1 to above result
11100101 + 1 = 11100110
so, -26 in 2's complement binary is 11100110
b)
Adding 01000110 and 11100110 in binary
01000110
11100110
-------------
(1)00101100
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 00101100
Verification:
---------------
sum = 00101100
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 101100 to decimal
101100
=> 1x2^5+0x2^4+1x2^3+1x2^2+0x2^1+0x2^0
=> 1x32+0x16+1x8+1x4+0x2+0x1
=> 32+0+8+4+0+0
=> 44
Answer: 44
This is correct since we can verify that 70+-26 = 44
So, there was no overflow.
c)
Number: -70
Let's convert this to two's complement binary
-70
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 70 successively by 2 until the quotient is 0
> 70/2 = 35, remainder is 0
> 35/2 = 17, remainder is 1
> 17/2 = 8, remainder is 1
> 8/2 = 4, remainder is 0
> 4/2 = 2, remainder is 0
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1000110
So, 70 of decimal is 1000110 in binary
So, 70 in normal binary is 01000110
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
01000110 is flipped to 10111001
Step 3:. Add 1 to above result
10111001 + 1 = 10111010
so, -70 in 2's complement binary is 10111010
Number: 26
Let's convert this to two's complement binary
26
Since this is a positive number. we can directly convert this into binary
Divide 26 successively by 2 until the quotient is 0
> 26/2 = 13, remainder is 0
> 13/2 = 6, remainder is 1
> 6/2 = 3, remainder is 0
> 3/2 = 1, remainder is 1
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 11010
So, 26 of decimal is 11010 in binary
so, 26 in 2's complement binary is 00011010
Adding 10111010 and 00011010 in binary
10111010
00011010
-------------
(0)11010100
-------------
Sum does not produces a carry
So, sum of these numbers in binary is 11010100
Verification:
---------------
sum = 11010100
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.
11010100 is flipped to 00101011
II. Add 1 to above result
00101011 + 1 = 00101100
III. Now convert this result to decimal value
Converting 101100 to decimal
101100
=> 1x2^5+0x2^4+1x2^3+1x2^2+0x2^1+0x2^0
=> 1x32+0x16+1x8+1x4+0x2+0x1
=> 32+0+8+4+0+0
=> 44
Answer: -44
This is correct since we can verify that -70+26 = -44
So, there was no overflow.
d)
Number: 70
Let's convert this to two's complement binary
70
Since this is a positive number. we can directly convert this into binary
Divide 70 successively by 2 until the quotient is 0
> 70/2 = 35, remainder is 0
> 35/2 = 17, remainder is 1
> 17/2 = 8, remainder is 1
> 8/2 = 4, remainder is 0
> 4/2 = 2, remainder is 0
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1000110
So, 70 of decimal is 1000110 in binary
so, 70 in 2's complement binary is 01000110
Number: 26
Let's convert this to two's complement binary
26
Since this is a positive number. we can directly convert this into binary
Divide 26 successively by 2 until the quotient is 0
> 26/2 = 13, remainder is 0
> 13/2 = 6, remainder is 1
> 6/2 = 3, remainder is 0
> 3/2 = 1, remainder is 1
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 11010
So, 26 of decimal is 11010 in binary
so, 26 in 2's complement binary is 00011010
Adding 01000110 and 00011010 in binary
01000110
00011010
-------------
(0)01100000
-------------
Sum does not produces a carry
So, sum of these numbers in binary is 01100000
Verification:
---------------
sum = 01100000
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 1100000 to decimal
1100000
=> 1x2^6+1x2^5+0x2^4+0x2^3+0x2^2+0x2^1+0x2^0
=> 1x64+1x32+0x16+0x8+0x4+0x2+0x1
=> 64+32+0+0+0+0+0
=> 96
Answer: 96
This is correct since we can verify that 70+26 = 96
So, there was no overflow.