This is based on the concept of b’s complement and (b + 1)’s complement of a base b number.
These are the respective formulae for finding the complements of a n-digit number let’s say X:
b’s complement of X = (b^n – 1 ) – X
(b+1)’s complement of X = b^n – X
For binary(base 2) we have 1’s and 2’s complement. For a n-bit number X:
1’s complement of X = (2^n – 1) – X
2’s complement of X = 2^n – X
We know the range of 2’s complement for a n-bit number is from -2^(n – 1) to +2^(n – 1) – 1.
For the range -8 to +7 we can see that n = 4
For representing negative numbers in 2’s complement:
2^n – absolute value of X
e.g. in the question lets represent -8
2^n – 8 = 2^n + (-8) = 2^4 + (-8) = 16 + (-8)
So in this way we are adding 16 to it to get the 2’s complement representation.