In: Computer Science
All decimal numbers must be converted to signed two’s complement form before working.
Use the least number of digits necessary (only using one sign bit) to represent the largest number in a given problem. The smaller number must be represented with the same number of bits.
If overflow occurs, indicate that with a note.
Show step by step addition.
15 + 6
14 + 18
31 + 5
1)
Number: 15
Let's convert this to two's complement binary
15
Since this is a positive number. we can directly convert this into binary
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
so, 15 in 2's complement binary is 01111
Number: 6
Let's convert this to two's complement binary
6
Since this is a positive number. we can directly convert this into binary
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
so, 6 in 2's complement binary is 00110
Adding 01111 and 00110 in binary
01111
00110
----------
(0)10101
----------
Sum does not produces a carry
So, sum of these numbers in binary is 10101
Verification:
---------------
sum = 10101
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.
10101 is flipped to 01010
II. Add 1 to above result
01010 + 1 = 01011
III. Now convert this result to decimal value
Converting 1011 to decimal
1011
=> 1x2^3+0x2^2+1x2^1+1x2^0
=> 1x8+0x4+1x2+1x1
=> 8+0+2+1
=> 11
Answer: -11
15+6 must be 21
This is not correct since we can verify that 15+6 not equals -11
So, there was an overflow.
2)
Number: 14
Let's convert this to two's complement binary
14
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
so, 14 in 2's complement binary is 001110
Number: 18
Let's convert this to two's complement binary
18
Since this is a positive number. we can directly convert this into binary
Divide 18 successively by 2 until the quotient is 0
> 18/2 = 9, remainder is 0
> 9/2 = 4, remainder is 1
> 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 10010
So, 18 of decimal is 10010 in binary
so, 18 in 2's complement binary is 010010
Adding 001110 and 010010 in binary
001110
010010
-----------
(0)100000
-----------
Sum does not produces a carry
So, sum of these numbers in binary is 100000
Verification:
---------------
sum = 100000
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.
100000 is flipped to 011111
II. Add 1 to above result
011111 + 1 = 100000
III. Now convert this result to decimal value
Converting 100000 to decimal
100000
=> 1x2^5+0x2^4+0x2^3+0x2^2+0x2^1+0x2^0
=> 1x32+0x16+0x8+0x4+0x2+0x1
=> 32+0+0+0+0+0
=> 32
Answer: -32
14+18 must be 32
This is not correct since we can verify that 14+18 not equals -32
So, there was an overflow.
3)
Number: 31
Let's convert this to two's complement binary
31
Since this is a positive number. we can directly convert this into binary
Divide 31 successively by 2 until the quotient 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 11111
So, 31 of decimal is 11111 in binary
so, 31 in 2's complement binary is 011111
Number: 5
Let's convert this to two's complement binary
5
Since this is a positive number. we can directly convert this into binary
Divide 5 successively by 2 until the quotient 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 101
So, 5 of decimal is 101 in binary
so, 5 in 2's complement binary is 000101
Adding 011111 and 000101 in binary
011111
000101
-----------
(0)100100
-----------
Sum does not produces a carry
So, sum of these numbers in binary is 100100
Verification:
---------------
sum = 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
31+5 must be 36
This is not correct since we can verify that 31+5 not equals -28
So, there was an overflow.