# two’s complement

I thought I’d do a quick write up on how to convert positive number to negative in two’s complement. This topic because it’s really simple and some sources make it more complicated that it should be. As you know, two’s complement is by far the most widely used binary scheme used by computers today. Its used because it makes arithmetic between positive and negative values much more intuitive.

## Method 1:

flip all the bits of the binary string and add 1.

For example:

1011 = (11 in decimal) becomes

0100 and then we add 1 so we get

0101

Easy enough. But there is one more easy method thats even quicker

## Method 2:

flip all the bits after the first LSB(least significant bit) that is 1

For example:

1011 = (11 in decimal) becomes

0101 because we flipped all the bits after the first 1 which is the first LSB(least significant bit) in this case.

I hope this method helped. Another side note is that when padding two’s complement numbers keep in mind that you pad negative numbers with 1s to the left and positive numbers with 0s to the right.

For example:

If we want to write 1011 (11 in decimal) using 8 digits we would write it as 00001011

and if we want to 0101 (-11 in decimal) using 8 digits we would write it as 11111011.