Data Representation: Two's compliment

Decimal to two's compliment binary

Two's compliment is a method that allows us to represent negative numbers in binary. It works by making the most significant bit negative. By the most significant bit we mean the bit in the column with the largest column heading

Example

An 8 bit number in two's compliment could be any number between -128 and 127 as can be seen below.

Biggest number possible.

-128 64   32   16   8    4    2    1    Total
0 1 1 1 1 1 1 1 127

Smallest number possible.

-128 64 32 16 8 4 2 1 Total
1 0 0 0 0 0 0 0 -128

As you can see the most significant bit, in this case 128, is negative. Note that the range of numbers that can be represented is still 256, including 0, we have just changed which numbers can be represented

If we were talking about a 5 bit number then the most significant bit would be -16 with a range of -16 to 15 able to be represented as seen below.

Biggest number possible.

-16 8 4 2 1 Total
0 1 1 1 1 15

Smallest number possible.

-16 8 4 2 1 Total
1 0 0 0 0 -16

There are several ways to convert from a negative denary number to a two's compliment binary number. The first is very similar to our method for converting from positive denary to binary.

When converting a negative number to two's compliment we know the most sigificant bit must be a 1 so the next step is to calculate how much we need to add back in order to get to our number. Let's convert the number -82 to two's compliment binary.

-128 + ? = -82

? = -82 + 128 = 46

Now that we have our number we can continue as we did before. Put a 1 in the column with the largest column heading that is not bigger than our number. Place zeros in any columns that we have gone past.

-128 64 32 16 8 4 2 1 Total
1 0 1

Subtract the column heading from our number and start again. In this case 46 - 32 = 14.

-128 64 32 16 8 4 2 1 Total
1 0 1 0 1

And repeat until the number to allocate is zero then any remaining columns are zero. So 14-8 = 6.

-128 64 32 16 8 4 2 1 Total
1 0 1 0 1 1

6-4 = 2

-128 64 32 16 8 4 2 1 Total
1 0 1 0 1 1 1 0 -82

Check by using a calculator -128 + 32 + 8 + 4 + 2 = -82

Negative denary to two's compliment binary practice

Click the button to get a number to convert

-128 64 32 16 8 4 2 1



Negative denary to two's compliment binary using the flip the bits method

You should also be aware of the other method. This involves converting the number to its positive binary equivalent, flip the bits and add one.

Action -128 64 32 16 8 4 2 1 Total
+ve 82 0 1 0 1 0 0 1 0 82
flip 1 0 1 0 1 1 0 1 -83
add 1 1 0 1 0 1 1 1 0 -82

Practice

Click the button below to generate a number to convert to two's compliment binary.

Action -128 64 32 16 8 4 2 1  Total 
Positive
Flip
add 1



© All materials created by and copyright S.Goff