Two's complement
Another way of storing integers is to use
 Two's Complement representation.

 

 

Example

To represent the number -13 as an 8-bit binary number...

Step 1 : Convert the positive number 13 into an 8-bit binary integer:

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

Step 2 : Change all the bits from 0 to 1 (or from 1 to 0.)

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

 

 

Step 3 : Add 1 - Perform a binary calculation.

1 1 1 1 0 0 1 0  
0 0 0 0 0 0 0 1 +
1 1 1 1 0 0 1 1  

Final answer : -13 in binary (using two's complement notation) is 11110011

 

Remember when adding in binary that
1 + 1 = 10
1 + 1 + 1 = 11

etc...
 

A strange system????

Yes...but the arithmetic works! Consider our example .......

The number 13 is represented as 00001101

and -13 is represented as 11110011

What do we get if we add these two numbers together (we should get 0)?

0 0 0 0 1 1 0 1
1 1 1 1 0 0 1 1
0 0 0 0 0 0 0 0

 

Another problem.....

How does the computer know if a number is positive or negative?

Does 11110011 represent -13 or does it represent (128+64+32+16+2+1) = 243?

The usual system is - the first (left) bit represents a sign bit (0 means the number is positive and 1 means it is negative).