All subjects · Computer Science · WCP01 Principles of Computer Science

Two's complement: representing signed integers

Edexcel IAL Computer Science · WCP01 Principles of Computer Science

Two's complement lets a fixed number of bits hold negative as well as positive whole numbers, and lets the same adder do subtraction (spec point 2.1.3).

Practise this in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise this lesson

How it works

In two's complement the most significant bit (MSB) has a negative place value. For 8 bits the place values are:

-128, 64, 32, 16, 8, 4, 2, 1

Example: 1101 0100 = -128 + 64 + 16 + 4 = -44.

Negating a number

To change the sign of a two's complement number (either way):

1. Invert every bit (0 to 1, 1 to 0).

2. Add 1.

Shortcut: copy bits from the right up to and including the first 1, then invert the rest.

Example: 44 = 0010 1100. Invert: 1101 0011. Add 1: 1101 0100 = -44.

Why it is needed

Worked example

Convert -75 to 8-bit two's complement.

  1. 75 = 0100 1011
  2. Invert: 1011 0100
  3. Add 1: 1011 0101
  4. Check: -128 + 53 = -75

Answer: 1011 0101

Key idea: MSB has place value -2n-1. Negate: invert then add 1. 8-bit range -128 to 127; one zero; subtraction by addition.

Check yourself

  1. What is the denary value of the 8-bit two's complement number 1010 0110?
    Show answer

    -90. -128 + 38 = -90.

  2. What is the denary value of the 8-bit two's complement number 0101 0011?
    Show answer

    83. The MSB is 0, so read as normal: 64 + 16 + 2 + 1 = 83.

  3. Convert -20 to 8-bit two's complement.
    Show answer

    11101100. 20 = 0001 0100; invert to 1110 1011; add 1 gives 1110 1100.

  4. Convert -1 to 8-bit two's complement.
    Show answer

    11111111. 1 = 00000001; invert to 11111110; add 1 gives 11111111.

  5. What is the most negative number that 8-bit two's complement can represent?
    Show answer

    -128. 10000000 = -128.

  6. What is the largest positive number that 12-bit two's complement can represent?
    Show answer

    2047. 211 - 1 = 2047.

  7. The 8-bit two's complement pattern 1101 1011 is negated. What is the denary value of the result?
    Show answer

    37. 1101 1011 = -37; negating gives +37 (0010 0101).

  8. Why is two's complement preferred to sign and magnitude?
    • It can represent larger positive numbers with the same bits
    • It has only one representation of zero and subtraction can be done by addition
    • It does not need an MSB
    • It stores fractions exactly
    Show answer

    It has only one representation of zero and subtraction can be done by addition. One zero, and the same adder works for subtraction.

Practise with instant feedback

Sources

Last updated 8 November 2026. Spotted a mistake? Tell us.