For positive numbers; 2’s Complement representation is the binary representation of the given positive number. For negative numbers, 2’s complement representation is the 2’s complement of the binary representation of its absolute value
Hence 2’s complement representation of
- 42 = 0101010
- 13 = 01101
- -42 = 1010110
- -13 = 10111
Now we do 2’s complement addition and ignore any carry. So, 42 + (-13) = 0101010 + 1110011 we get 0011101 = 29.
For (-42) - (-13) = (-42) + 13 = 1010110 + 0001101 = 1100011 = –29.
(We append 0s before positive and 1s before negative numbers (sign extension) to make the number of bits the same while doing addition)