In order to get the opposite of a number (additive inverse) in two’s complement we have to take the complement of each bit (0 –> 1 and 1 –> 0) of its representation and then add 1.

In Python, we can negate each bit of a number by using the symbol ~.

So, guess what we get if we negate the bits of a number (without adding 1) and then take the opposite of the resulting number.

### Like this:

Like Loading...

*Related*