In: Computer Science
Please read carefully. Using the minimum number of digits in 2’s complement notation, perform 25 – 18 (subtraction by preserving addition). Show all the significant steps in your work by indicating the starting values, sign conversion and the addition operation aligning all numbers including the carry values in each position using the Courier New font. Indicate the final value as a decimal.
to represent 25, or -18 we need 6 bits.
so, using 6 bits for calculations..
Number: 25
Let's convert this to two's complement binary
25
Since this is a positive number. we can directly convert this into binary
Divide 25 successively by 2 until the quotient is 0
> 25/2 = 12, remainder is 1
> 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 11001
So, 25 of decimal is 11001 in binary
so, 25 in 2's complement binary is 011001
Number: -18
Let's convert this to two's complement binary
-18
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
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 normal binary is 010010
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
010010 is flipped to 101101
Step 3:. Add 1 to above result
101101 + 1 = 101110
so, -18 in 2's complement binary is 101110
Adding 011001 and 101110 in binary
(c)1110000 <- these are carry bits for the calculation.
011001
101110
-----------
(1)000111
-----------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 000111
Verification:
---------------
sum = 000111
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 111 to decimal
111
=> 1x2^2+1x2^1+1x2^0
=> 1x4+1x2+1x1
=> 4+2+1
=> 7
Answer: 7
This is correct since we can verify that 25+-18 = 7
So, there was no overflow.