Home » Uncategorized » Two’s complement and increase by 1

Two’s complement and increase by 1

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: