In an 8 bit representation of computer system the decimal number 26 has to be subtracted from 22 and the result in binary 2's complement is _________
Explanation
The correct answer is 00000100
Two's complement representation, or, in other words, signed notation - the first bit tells about the sign.
The convention is that a number with a leading 1 is negative, while a leading 0 denotes a positive value. In an 8-bit representation, we can write any number from -128 to 127. The name comes from the fact that a negative number is a two's complement of a positive one.
26 has to be subtracted from 22 hence result will be negative. So, to avoid negative results, 2's complement is to be used. We have to find 2's complement of the Subtrahend (26) and add it to the minuend (22). To calculate 2's complement, first, we need to find the 1's complement by swapping all 1 to
0 and all 0 to 1 and then we need to add 1 to it:
for 22, Binary = 10110
for 26, Binary = 11010, 1's Complement = 00101, 2's Complement = 00110
Addition = 10110 + 00110 = 11100
now in the answer obtained, there is no carry generated. In this case, we will have to find 2's
complement of the result in order to find the final result.
11100 = 1's Complement = 00011, 2's Complement = 00100
In 8 bit representation, we will write 00000100
hence our answer is 00000100