We have seen how two's complement can be used to represent negative numbers. We now need to look at how we can convert a positive number into a negative.

Let's start off with an example, to convert 6 to -6. First of all we write down the binary representation of 6. The numbers in the top row represent the column values for each binary digit. So 4 + 2 = 6.

Starting from the right, we copy all of the binary digits until we see a 1 as shown in the diagram above. These are then copied over to the answer. In this case we copy over the bits 10, as this is the first 1 bit we read in from the right hand side. Finally we simply complement, or flip the bits, of the rest.

Positive representation

0

1

1

0

Copy over first right hand bits

 

 

1

0

Copy over the rest of the bits

0

1

1

0

Complement the remainder

1

0

1

0

The above table shows the answer worked through. The shaded values are the bits which are complemented. Let us look at the same table for 3 and 4.

Positive representation

0

0

1

1

Copy over first right hand bits

 

 

 

1

Complement the remainder

1

1

0

1

Positive representation

0

1

0

0

Copy over first right hand bits

 

1

0

0

Complement the remainder

1

0

0

0

So the algorithm we follow is.

  • Copy over all bits, starting from the right hand side, until a 1 is encountered.
  • Complement remaining bits.

In order to convert a negative number to a positive number, we follow the exact same algorithm.