In: Computer Science
Identify the following numbers using 2’s complement by making
suitable assumptions:
a. 1710 + 610
b. 2110 – 410
c. -1310 - 2010
Hello there, Hope you're doing fine. I hope you know that 2s complement is an alternative binary representation to make operations on binary numbers easier. Usually in the cases where a negative number is to be represented, 2s complement is introduced.
So, to convert a given number to 2s complement, you must first convert it to its 1s complement form and then add 1 to the least significant bit. Keep in mind that, to convert a number to 1s complement, you simply invert every individual bit in it.
Here, I am assuming the 10s on the end are actually subscripts
to show they are Decimal numbers.
1. (17)10 + (6)10 (converting to binary[base 2]) -> 10001 + 110 = 10001 + 00110 = 10111 (converting to decimal[base 10]) -> 23.
Here, no 2s complement calculation was required as all numbers were positive.
2. (21)10 - (4)10 (converting to binary) -> 10101 + -(00100), since -4 is a negative number, here we require 2s complement calculation.
Thus, it become => 10101 + 11100
performing binary addition and discarding the end around carry since positive number (21) was the bigger number;
10101 + 11100 = 1 10001, discarding end around carry(MSB) as 21 is bigger, result = 10001 = (17)10
3. -(13)10 - (20)10 (converting to binary) -> -(1101)+-(10100) Here, both are negative, so the digits are balanced and their complements calculated.
-(001101) + -(010100) (2s complement calculation) -> 110011 + 101100
Now, simple addition is performed and the end around carry (MSB) is discarded, the final result's 2s complement be calculated and presented with a negative sign since both original numbers were negative.
110011 + 101100 = 1 011111
Discarding the end around carry, final result -> 011111
Converting to 2s complement, => 100001 (converting to decimal) -> (33)10
adding negative sign, -33
I hope this clears up your doubt. Have a Good day and happy learning.