In: Computer Science
add the following numbers using 16-bit 2's complement.
show all the steps and calculations.
Please also show steps to verify that the answer is correct.
2368 and -772

Number: 2368
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into
binary
Divide 2368 successively by 2 until the quotient is 0
> 2368/2 = 1184, remainder is 0
> 1184/2 = 592, remainder is 0
> 592/2 = 296, remainder is 0
> 296/2 = 148, remainder is 0
> 148/2 = 74, remainder is 0
> 74/2 = 37, remainder is 0
> 37/2 = 18, remainder is 1
> 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 100101000000
So, 2368 of decimal is 100101000000 in binary
Adding 4 zeros on left hand side of this number to make this of
length 16
so, 2368 in 2's complement binary is 0000100101000000
Number: -772
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 772 successively by 2 until the quotient is 0
> 772/2 = 386, remainder is 0
> 386/2 = 193, remainder is 0
> 193/2 = 96, remainder is 1
> 96/2 = 48, remainder is 0
> 48/2 = 24, remainder is 0
> 24/2 = 12, remainder is 0
> 12/2 = 6, remainder 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 1100000100
So, 772 of decimal is 1100000100 in binary
Adding 6 zeros on left hand side of this number to make this of
length 16
So, 772 in normal binary is 0000001100000100
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to
0.
0000001100000100 is flipped to 1111110011111011
Step 3:. Add 1 to above result
1111110011111011 + 1 = 1111110011111100
so, -772 in 2's complement binary is 1111110011111100
Adding 0000100101000000 and 1111110011111100 in
binary
0000100101000000
1111110011111100
---------------------
(1)0000011000111100
---------------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 0000011000111100
Verification:
---------------
sum = 0000011000111100
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=> 11000111100
=>
1x2^10+1x2^9+0x2^8+0x2^7+0x2^6+1x2^5+1x2^4+1x2^3+1x2^2+0x2^1+0x2^0
=> 1x1024+1x512+0x256+0x128+0x64+1x32+1x16+1x8+1x4+0x2+0x1
=> 1024+512+0+0+0+32+16+8+4+0+0
=> 1596
Answer: 1596
This is correct since we can verify that 2368+-772 = 1596
So, there was no overflow.