Study Guide

Two’s Complement

How a computer stores negative whole numbers in binary by making the leftmost bit worth −128, how to convert both ways between denary or binary and 8-bit two’s complement, and the range it can store.

Lesson 1.5 Data Representation

For: Cambridge IGCSE Computer Science learners, or anyone who can already convert between binary and denary and has met overflow

Stage: Think

Going backwards past zero

A fictional toy car has a mileage counter with three wheels, showing 000 to 999. It shows 000, and the car is pushed one mile backwards, so the wheels roll back.

Think it through

What do the wheels show after one mile backwards? If the toy company agreed that this reading means −1, what would 998 mean?

Show what happens

The wheels show 999, which can be agreed to mean −1. Then 998 means −2, 997 means −3, and so on: the readings just below 1000 stand for numbers just below zero.

Think it through

In an 8-bit register, which pattern gives 0000 0000 when 0000 0001 is added to it, if the carry out of the leftmost column is lost? What number could that pattern stand for?

Show what happens

1111 1111: adding 1 makes every column carry and leaves 0000 0000, just as the counter wraps from 999 to 000. A pattern that gives 0 when 1 is added behaves like −1, so 1111 1111 can stand for −1.

Stage: Discover

A column worth −128

The pattern 1111 1111 should stand for −1. But with the usual columns it is worth 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255.

Think it through

The seven right-hand columns, 64 + 32 + 16 + 8 + 4 + 2 + 1, add up to 127. For 1111 1111 to be worth −1 in total, what would the leftmost column have to be worth?

Show what happens

−128: −128 + 127 = −1. So if the leftmost column is worth −128 instead of +128, the pattern 1111 1111 is worth −1 and every other pattern still gets a sensible value.

This is the two’s complement system. An 8-bit two’s complement number has the usual columns, except that the leftmost column, the most significant bit, is worth −128 and not +128:

From left to right, the eight columns are worth −128, 64, 32, 16, 8, 4, 2 and 1.

A number that starts with 0 is positive: it is read in the ordinary way. A number that starts with 1 is negative, because the −128 is included.

  1. Write the bits under the columns. 1011 0100 has 1s in the −128, 32, 16 and 4 columns.
  2. Add the values of the columns that hold a 1. −128 + 32 + 16 + 4.
  3. Add the positive columns first, then the negative one. 32 + 16 + 4 = 52, and −128 + 52 = −76.
  4. Check the sign. The leftmost bit is 1, so the number should be negative. It is.

Check your understanding

What is the 8-bit two’s complement number 1000 0101 in denary?
Show the answer

Answer: B. −123, because the −128 column is on and 4 + 1 is added: −123.

−128 + 4 + 1 = −123.

Two’s complement to denary
8-bit two’s complementDenary
0000 101010
1111 1110
1000 0001
1100 1000
0111 1111
1000 0000

    Show the completed table
    8-bit two’s complementDenary
    0000 101010
    1111 1110−2
    1000 0001−127
    1100 1000−56
    0111 1111127
    1000 0000−128

    Stage: Predict

    Writing a negative number

    Think it through

    Using the columns −128, 64, 32, 16, 8, 4, 2 and 1, each at most once, how could you make −45? Which column must you start with, and what is left to make after it?

    Show a model answer

    Start with −128, the only negative column. Then −45 − (−128) = 83 is left to make from the positive columns. 83 = 64 + 16 + 2 + 1, so the 64, 16, 2 and 1 columns are on. The pattern is 1101 0011, and −128 + 64 + 16 + 2 + 1 = −45.

    There is also a shortcut that always works: to write the negative of a number, invert every bit (swap each 0 for 1 and each 1 for 0), then add 1.

    1. Write the positive number. 45 is 0010 1101.
    2. Invert every bit. 1101 0010.
    3. Add 1. 1101 0010 + 1 = 1101 0011.
    4. Check. The result is the same as the one made from the columns: 1101 0011.

    Why does it work? A number and its inverted form add up to 1111 1111, because each column has one 0 and one 1: 0010 1101 + 1101 0010 = 1111 1111. But 1111 1111 is −1. So the inverted form is −1 minus the number, and adding 1 gives minus the number: −45.

    Going back is the same: invert and add 1 again. 1101 0011 inverts to 0010 1100, and adding 1 gives 0010 1101, which is 45.

    A positive number needs no change at all: it is written in ordinary binary with a 0 at the left. 37 is 0010 0101.

    Check your understanding

    What is −20 as an 8-bit two’s complement number?
    Show the answer

    Answer: C. 1110 1100, which is 20 inverted, then 1 added.

    20 is 0001 0100. Inverting gives 1110 1011, and adding 1 gives 1110 1100. Check: −128 + 64 + 32 + 8 + 4 = −20.

    Denary to 8-bit two’s complement
    Denary8-bit two’s complement
    −11111 1111
    37
    −12
    −100
    −128

      Show the completed table
      Denary8-bit two’s complement
      −11111 1111
      370010 0101
      −121111 0100
      −1001001 1100
      −1281000 0000

      Stage: Explain

      How far the numbers go

      Think it through

      In 8-bit two’s complement, what is the largest number you can write, and the smallest (the most negative)? Which patterns are they?

      Show what happens

      The largest is 0111 1111 = 127 (the −128 column off, all the others on). The smallest is 1000 0000 = −128 (only the −128 column on).

      The range of 8-bit two’s complement is −128 to 127. That is 256 different whole numbers, one for each pattern of eight bits. There is one more negative number than positive ones, because zero uses one of the patterns that start with 0.

      A number outside the range cannot be stored. In a register, adding 1 to 0111 1111 (127) gives 1000 0000, which reads as −128: just as an unsigned register wraps from 255 to 0, a two’s complement register wraps from 127 to −128.

      Check your understanding

      What is the range of whole numbers an 8-bit two’s complement register can store?
      Show the answer

      Answer: A. −128 to 127

      −128 to 127 contains 128 negative numbers, zero and 127 positive numbers: 256 numbers in all, the same as the 256 patterns of eight bits.

      Stage: Discover

      Binary numbers with a sign

      So far each negative number has been written in denary. A number can also be written in binary with a minus sign in front: −1011 means minus 11 (−(8 + 2 + 1)).

      Think it through

      How could you store −1011 (minus 11) in an 8-bit register? Write down your plan for the pattern, and then try it.

      Show a model answer

      Write 1011 as eight bits: 0000 1011. Invert: 1111 0100. Add 1: 1111 0101. Check: −128 + 64 + 32 + 16 + 4 + 1 = −11.

      Binary numbers with a sign to 8-bit two’s complement
      Number8-bit two’s complement
      −10111111 0101
      +101101
      −101101
      −1100

        Show the completed table
        Number8-bit two’s complement
        −10111111 0101
        +1011010010 1101
        −1011011101 0011
        −11001111 0100

        Now the other way: read the denary value, then write it as binary with a sign. For a negative number, invert and add 1 to find the size, and put the minus sign in front. Write positive numbers without leading zeros.

        8-bit two’s complement to denary and to binary with a sign
        8-bit two’s complementDenaryBinary with a sign
        1111 0100−12−1100
        1110 0111
        0101 0110
        1000 1100

          Show the completed table
          8-bit two’s complementDenaryBinary with a sign
          1111 0100−12−1100
          1110 0111−25−11001
          0101 0110861010110
          1000 1100−116−1110100

          Stage: Apply

          Use it somewhere new

          A fictional weather station stores each temperature in degrees Celsius as an 8-bit two’s complement number. A reading arrives as 1110 0111.

          Apply it

          What temperature does 1110 0111 stand for?
          Show the answer

          Answer: D. −25 °C, because −128 + 64 + 32 + 4 + 2 + 1 = −25.

          −128 + 64 + 32 + 4 + 2 + 1 = −128 + 103 = −25. It is a cold reading, which is why the leftmost bit is a 1.

          A fictional freezer logger stores its temperature in the same way, and needs to record −18 °C.

          Apply it

          Which pattern stores −18?
          Show the answer

          Answer: B. 1110 1110, which is 18 inverted, then 1 added.

          18 is 0001 0010. Inverting gives 1110 1101 and adding 1 gives 1110 1110. Check: −128 + 64 + 32 + 8 + 4 + 2 = −18.

          Apply it

          A register holds 0111 1111 (127), and 1 is added to it. What does it hold now, read as an 8-bit two’s complement number?
          Show the answer

          Answer: C. −128, because 0111 1111 + 1 = 1000 0000, which reads as −128.

          0111 1111 + 0000 0001 = 1000 0000, and in two’s complement 1000 0000 is −128. The true answer, 128, is outside the range −128 to 127, so the stored result is wrong.

          Apply it

          Aisha says: “1000 0000 is minus nought, because the leftmost bit means negative and the rest is zero.” What is wrong with her reasoning?
          Show the answer

          Answer: A. The leftmost bit is not a minus sign: it is a column worth −128, so 1000 0000 is −128.

          1000 0000 has only the −128 column on, so its value is −128. In two’s complement the leftmost bit is part of the value, not a sign in front of it.

          Stage: Consolidate

          Bring it together

          Think it through

          Without looking back, explain to a friend how to find the 8-bit two’s complement pattern for −9, and how you could check your answer.

          Show a model answer

          9 is 0000 1001. Invert every bit: 1111 0110. Add 1: 1111 0111. To check, add the columns: −128 + 64 + 32 + 16 + 4 + 2 + 1 = −128 + 119 = −9.

          Check your understanding

          How many different whole numbers can an 8-bit two’s complement register store, counting zero?
          Show the answer

          Answer: C. 256, one for each pattern of eight bits.

          Eight bits always make 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 256 patterns. Two’s complement shares them out as −128 to 127.

          Go deeper Beyond the specification: why computers like two’s complement

          Adding a positive and a negative two’s complement number needs no special rules: it is the same column addition as before. For example, 10 + (−5): 0000 1010 + 1111 1011 = 1 0000 0101. Drop the carry out of the leftmost column and the register holds 0000 0101, which is 5. The carry out is simply dropped in two’s complement addition, and the answer is correct as long as it lies in the range −128 to 127. Subtraction can then be done by adding the negative. This is one reason nearly every computer uses it.

          • Two’s complement stores negative numbers in binary by making the leftmost column worth −128 (in 8 bits). The other columns are the usual 64, 32, 16, 8, 4, 2 and 1.
          • A number whose leftmost bit is 0 is positive, and is read as ordinary binary. A leftmost bit of 1 means the −128 is included, so the number is negative.
          • To read a number, add the values of the columns that hold a 1, with −128 for the leftmost. To write a negative number, either make it from the columns, or write the positive form, invert every bit and add 1. Inverting and adding 1 also turns a negative pattern back into its positive form.
          • The 8-bit range is −128 to 127: 256 numbers, one for each pattern. Outside it, the register wraps round and overflows.
          • The leftmost bit is not a minus sign in front of a number: it is a column with a value of its own.

          Sources and scope

          • What this lesson is. The fifth lesson of the Data Representation module, written for this site. It teaches point 6 of Cambridge IGCSE Computer Science 1.1 (8-bit two’s complement) against the 2026 to 2028 syllabus (version 6). Its curriculum links are provisional: no link has been verified by the site owner. They show where the lesson may help with a course and imply no review or endorsement by any examination board.
          • Original material. The toy car’s mileage counter, the weather station, the freezer logger and Aisha’s claim are fictional examples written for this lesson.
          • Simplified on purpose. Only 8-bit two’s complement is taught; other word lengths follow the same pattern with a different leftmost column. Other ways of storing negative numbers, such as sign and magnitude and one’s complement, are not taught. The optional extension on adding negative numbers goes beyond what 0478 point 6 asks for.