In: Computer Science

a)
Number: 14
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 14 successively by 2 until the quotient is 0
> 14/2 = 7, remainder 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 1110
So, 14 of decimal is 1110 in binary
Adding 1 zeros on left hand side of this number to make this of length 5
so, 14 in 2's complement binary is 01110
Number: 2
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 2 successively by 2 until the quotient is 0
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 10
So, 2 of decimal is 10 in binary
Adding 3 zeros on left hand side of this number to make this of length 5
so, 2 in 2's complement binary is 00010
Adding 01110 and 00010 in binary
01110
00010
----------
(0)10000
----------
Sum does not produces a carry
So, sum of these numbers in binary is 10000
Verification:
---------------
sum = 10000
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.
10000 is flipped to 01111
II. Add 1 to above result
01111 + 1 = 10000
III. Now convert this result to decimal value
=> 10000
=> 1x2^4+0x2^3+0x2^2+0x2^1+0x2^0
=> 1x16+0x8+0x4+0x2+0x1
=> 16+0+0+0+0
=> 16
Answer: -16
14+2 must be 16
This is not correct since we can verify that 14+2 not equals -16
So, there was an overflow.
b)
Number: 14
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 14 successively by 2 until the quotient is 0
> 14/2 = 7, remainder 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 1110
So, 14 of decimal is 1110 in binary
Adding 2 zeros on left hand side of this number to make this of length 6
so, 14 in 2's complement binary is 001110
Number: -6
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 6 successively by 2 until the quotient is 0
> 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 110
So, 6 of decimal is 110 in binary
Adding 3 zeros on left hand side of this number to make this of length 6
So, 6 in normal binary is 000110
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
000110 is flipped to 111001
Step 3:. Add 1 to above result
111001 + 1 = 111010
so, -6 in 2's complement binary is 111010
Adding 001110 and 111010 in binary
001110
111010
-----------
(1)001000
-----------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 001000
Verification:
---------------
sum = 001000
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=> 1000
=> 1x2^3+0x2^2+0x2^1+0x2^0
=> 1x8+0x4+0x2+0x1
=> 8+0+0+0
=> 8
Answer: 8
This is correct since we can verify that 14+-6 = 8
So, there was no overflow.
c)
Number: 62
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 62 successively by 2 until the quotient is 0
> 62/2 = 31, remainder is 0
> 31/2 = 15, remainder is 1
> 15/2 = 7, remainder is 1
> 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 111110
So, 62 of decimal is 111110 in binary
so, 62 in 2's complement binary is 111110
Number: 2
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 2 successively by 2 until the quotient is 0
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 10
So, 2 of decimal is 10 in binary
Adding 4 zeros on left hand side of this number to make this of length 6
so, 2 in 2's complement binary is 000010
Adding 111110 and 000010 in binary
111110
000010
-----------
(1)000000
-----------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 000000
Verification:
---------------
sum = 000000
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=>
=>
=>
=>
=> 0
Answer: 0
62+2 must be 64
This is not correct since we can verify that 62+2 not equals 0
So, there was an overflow.
d)
Number: -15
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 15 successively by 2 until the quotient is 0
> 15/2 = 7, remainder is 1
> 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 1111
So, 15 of decimal is 1111 in binary
Adding 4 zeros on left hand side of this number to make this of length 8
So, 15 in normal binary is 00001111
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
00001111 is flipped to 11110000
Step 3:. Add 1 to above result
11110000 + 1 = 11110001
so, -15 in 2's complement binary is 11110001
Number: -10
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 10 successively by 2 until the quotient is 0
> 10/2 = 5, remainder is 0
> 5/2 = 2, remainder is 1
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1010
So, 10 of decimal is 1010 in binary
Adding 4 zeros on left hand side of this number to make this of length 8
So, 10 in normal binary is 00001010
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
00001010 is flipped to 11110101
Step 3:. Add 1 to above result
11110101 + 1 = 11110110
so, -10 in 2's complement binary is 11110110
Adding 11110001 and 11110110 in binary
11110001
11110110
-------------
(1)11100111
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 11100111
Verification:
---------------
sum = 11100111
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.
11100111 is flipped to 00011000
II. Add 1 to above result
00011000 + 1 = 00011001
III. Now convert this result to decimal value
=> 11001
=> 1x2^4+1x2^3+0x2^2+0x2^1+1x2^0
=> 1x16+1x8+0x4+0x2+1x1
=> 16+8+0+0+1
=> 25
Answer: -25
This is correct since we can verify that -15+-10 = -25
So, there was no overflow.
e)
Number: 125
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 125 successively by 2 until the quotient is 0
> 125/2 = 62, remainder is 1
> 62/2 = 31, remainder is 0
> 31/2 = 15, remainder is 1
> 15/2 = 7, remainder is 1
> 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 1111101
So, 125 of decimal is 1111101 in binary
Adding 1 zeros on left hand side of this number to make this of length 8
so, 125 in 2's complement binary is 01111101
Number: 2
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 2 successively by 2 until the quotient is 0
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 10
So, 2 of decimal is 10 in binary
Adding 6 zeros on left hand side of this number to make this of length 8
so, 2 in 2's complement binary is 00000010
Adding 01111101 and 00000010 in binary
01111101
00000010
-------------
(0)01111111
-------------
Sum does not produces a carry
So, sum of these numbers in binary is 01111111
Verification:
---------------
sum = 01111111
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=> 1111111
=> 1x2^6+1x2^5+1x2^4+1x2^3+1x2^2+1x2^1+1x2^0
=> 1x64+1x32+1x16+1x8+1x4+1x2+1x1
=> 64+32+16+8+4+2+1
=> 127
Answer: 127
This is correct since we can verify that 125+2 = 127
So, there was no overflow.