Kramizo
Log inSign up free
HomeCIE IGCSE Computer ScienceData representation: two's complement (representation of negative numbers and subtraction)
CIE · IGCSE · Computer Science · Revision Notes

Data representation: two's complement (representation of negative numbers and subtraction)

1,955 words · Last updated May 2026

Ready to practise? Test yourself on Data representation: two's complement (representation of negative numbers and subtraction) with instantly-marked questions.
Practice now →

What you'll learn

This revision guide covers how computers represent negative numbers using two's complement notation and how this system enables binary subtraction. You'll learn the method for converting between denary and two's complement, understand why this system is used in computing, and master binary arithmetic operations that appear frequently in CIE IGCSE Computer Science examinations.

Key terms and definitions

Two's complement — A system for representing both positive and negative integers in binary, where the most significant bit (MSB) acts as the sign bit and has a negative place value.

Sign bit — The leftmost bit in a two's complement number that determines whether the value is positive (0) or negative (1).

Most Significant Bit (MSB) — The leftmost bit in a binary number, which has the highest place value; in two's complement, this bit has a negative place value.

Overflow — An error condition that occurs when the result of a binary calculation is too large to be represented within the available number of bits.

Binary subtraction — The operation of subtracting one binary number from another, typically performed using two's complement addition in computer systems.

Denary — The base-10 number system used in everyday mathematics, consisting of digits 0-9.

Invert — To flip all bits in a binary number, changing 0s to 1s and 1s to 0s (also called finding the one's complement).

Least Significant Bit (LSB) — The rightmost bit in a binary number, which has the lowest place value (always represents 2⁰ or 1).

Core concepts

Why two's complement is used

Computers use two's complement notation because it provides several advantages over other methods of representing negative numbers:

  • Simplified arithmetic circuits: Addition and subtraction can be performed using the same hardware circuitry, reducing cost and complexity
  • Single representation of zero: Unlike sign-and-magnitude notation, there is only one way to represent zero (all bits set to 0)
  • Consistent overflow detection: Overflow can be detected using straightforward logic rules
  • Direct comparison: Numbers can be compared using the same logic as unsigned integers, except for the sign bit

Alternative systems like sign-and-magnitude (where the MSB simply indicates positive or negative) require separate circuits for addition and subtraction, making them impractical for modern processors.

Understanding two's complement place values

In a two's complement binary number, the place values differ from standard unsigned binary only in the MSB, which has a negative value.

For an 8-bit two's complement number:

Bit position 7 6 5 4 3 2 1 0
Place value -128 64 32 16 8 4 2 1

Key points about place values:

  • The MSB (bit 7 in 8-bit notation) has a place value of -128
  • All other bits have positive place values as in standard binary
  • The range of values for 8-bit two's complement is -128 to +127
  • Positive numbers always have a 0 as the MSB
  • Negative numbers always have a 1 as the MSB

For other bit lengths, the MSB value is always -2^(n-1) where n is the number of bits.

Converting denary to two's complement

For positive numbers:

  1. Convert the denary number to binary as normal
  2. Pad with leading zeros to fill the required number of bits
  3. The MSB will be 0, confirming it's positive

Example: Convert +45 to 8-bit two's complement

  • 45 in binary = 101101
  • Pad to 8 bits: 00101101
  • MSB is 0, so this is positive

For negative numbers:

Method 1 (Standard approach):

  1. Convert the absolute value to binary
  2. Pad with leading zeros to the required bit length
  3. Invert all the bits (change 0→1 and 1→0)
  4. Add 1 to the result

Example: Convert -45 to 8-bit two's complement

  • 45 in binary = 101101
  • Pad to 8 bits: 00101101
  • Invert all bits: 11010010
  • Add 1: 11010011
  • Result: 11010011 represents -45

Method 2 (Working from the right):

  1. Convert the absolute value to binary
  2. Copy bits from right to left until you've copied the first 1
  3. Invert all remaining bits to the left

This method produces the same result but may be faster for some students.

Converting two's complement to denary

If MSB is 0 (positive number):

Simply convert the binary number to denary using standard place values.

Example: 01101010 in two's complement

  • (0×-128) + (1×64) + (1×32) + (0×16) + (1×8) + (0×4) + (1×2) + (0×1)
  • = 0 + 64 + 32 + 0 + 8 + 0 + 2 + 0
  • = +106

If MSB is 1 (negative number):

Method 1 (Using place values): Calculate using the negative value of the MSB

Example: 11010011 in two's complement

  • (1×-128) + (1×64) + (0×32) + (1×16) + (0×8) + (0×4) + (1×2) + (1×1)
  • = -128 + 64 + 0 + 16 + 0 + 0 + 2 + 1
  • = -45

Method 2 (Reverse process):

  1. Subtract 1 from the binary number
  2. Invert all bits
  3. Convert to denary
  4. Add a negative sign

This method is useful for checking your work but the place value method is typically faster.

Binary subtraction using two's complement

Rather than performing direct subtraction, computers convert subtraction problems into addition problems using two's complement.

To calculate A - B:

  1. Convert B to two's complement (find -B)
  2. Add A + (-B) using binary addition
  3. Discard any carry bit beyond the available bits
  4. Check for overflow if necessary

Example: 25 - 18 in 8-bit binary

  • 25 in binary: 00011001
  • 18 in binary: 00010010
  • -18 in two's complement: 11101110 (invert 00010010 to get 11101101, then add 1)
  • Add: 00011001 + 11101110
  00011001
+ 11101110
-----------
 100000111
  • Discard the carry bit (the 1 beyond 8 bits)
  • Result: 00000111 = 7 (correct, as 25-18=7)

This technique works because A - B = A + (-B), and two's complement provides an efficient representation of -B.

Detecting overflow

Overflow occurs when a calculation produces a result that cannot be represented within the available number of bits. This is a critical concept in computer arithmetic.

Overflow detection rules for two's complement addition:

  • Positive + Positive = Negative: Overflow has occurred (impossible in reality)
  • Negative + Negative = Positive: Overflow has occurred (impossible in reality)
  • Positive + Negative: Overflow cannot occur (results always fit within range)

Example of overflow: Add 100 + 50 in 8-bit two's complement

  • 100 in binary: 01100100
  • 50 in binary: 00110010
  • Add them:
  01100100
+ 00110010
-----------
  10010110
  • Result: 10010110 = -106 in two's complement
  • This is incorrect (should be 150)
  • Overflow occurred because 150 > 127 (maximum positive value in 8-bit two's complement)
  • We can detect this because two positive numbers (MSB=0) produced a negative result (MSB=1)

Worked examples

Example 1: Converting negative denary to two's complement (3 marks)

Question: Convert -58 to an 8-bit two's complement binary number. Show your working.

Mark scheme answer:

Step 1: Convert 58 to binary

  • 58 = 32 + 16 + 8 + 2
  • 58 = 00111010 (1 mark for correct binary conversion)

Step 2: Invert all bits

  • 11000101 (1 mark for correct inversion)

Step 3: Add 1

  • 11000101 + 1 = 11000110
  • Final answer: 11000110 (1 mark for adding 1 correctly)

Examiner note: All working must be shown. Students who write only the final answer without showing the three steps will receive only 1 mark.

Example 2: Binary subtraction using two's complement (4 marks)

Question: Using 8-bit two's complement binary, calculate 52 - 29. Show all working.

Mark scheme answer:

Step 1: Convert both numbers to 8-bit binary

  • 52 = 00110100 (1 mark)
  • 29 = 00011101

Step 2: Find the two's complement of 29 to get -29

  • Invert: 11100010
  • Add 1: 11100011 (1 mark for correct -29)

Step 3: Add 52 + (-29)

  00110100
+ 11100011
-----------
 100010111

(1 mark for correct addition)

Step 4: Discard carry bit, final result

  • 00010111 = 16 + 4 + 2 + 1 = 23 (1 mark for correct answer)

Examiner note: The carry bit beyond 8 bits must be discarded. This is normal in two's complement subtraction and does not indicate overflow.

Example 3: Converting two's complement to denary (2 marks)

Question: The 8-bit two's complement binary number 10110101 represents a denary value. Calculate this value.

Mark scheme answer:

Using place values with negative MSB:

  • (1×-128) + (0×64) + (1×32) + (1×16) + (0×8) + (1×4) + (0×2) + (1×1) (1 mark for method)
  • = -128 + 32 + 16 + 4 + 1
  • = -75 (1 mark for correct answer)

Examiner note: Students must show the place value calculation. Simply stating the answer without working receives only 1 mark.

Common mistakes and how to avoid them

  • Forgetting to add 1 after inverting: When converting negative denary to two's complement, students often invert the bits but forget to add 1. Remember: invert, then add 1 — both steps are essential.

  • Not padding to the correct number of bits: Always pad positive binary numbers with leading zeros to reach the required bit length before inverting. If you start with 6 bits when 8 are required, your answer will be wrong.

  • Treating the MSB as positive in negative numbers: When converting two's complement to denary, remember the MSB has a negative place value. For 8-bit numbers, bit 7 = -128, not +128.

  • Discarding carry bits incorrectly: In two's complement subtraction, always discard the final carry bit beyond the available bits — this is normal and correct. However, don't confuse this with overflow.

  • Misidentifying overflow: Overflow only occurs when adding two numbers with the same sign produces a result with the opposite sign. Adding a positive and negative number cannot produce overflow.

  • Using the wrong range: For n-bit two's complement, the range is -2^(n-1) to 2^(n-1)-1. For 8 bits, this is -128 to +127, not -128 to +128.

Exam technique for "Data representation: two's complement (representation of negative numbers and subtraction)"

  • "Show your working" means show all steps: Questions worth 3+ marks requiring conversions or subtraction always expect to see intermediate steps. Write out the binary at each stage (original, inverted, after adding 1).

  • Command word "Calculate" requires method marks: Even if your final answer is wrong, you can earn marks for correct method. For conversion questions, show the place value calculation or the invert-and-add-1 steps.

  • Check the number of bits specified: Questions will specify 8-bit, 16-bit, or occasionally other lengths. Using the wrong number of bits loses marks even if your method is correct. Circle or underline the bit length when you first read the question.

  • Overflow questions test understanding, not just calculation: If asked whether overflow occurs, explain why using the sign bits (e.g., "Two positive numbers produced a negative result"). Simply stating "yes" or "no" typically earns only 1 mark when 2-3 are available.

Quick revision summary

Two's complement represents negative numbers in binary by making the MSB a sign bit with negative place value. Convert negative denary to two's complement by: converting the absolute value to binary, inverting all bits, then adding 1. Convert two's complement to denary using place values where the MSB is negative. Perform binary subtraction by adding the two's complement of the subtrahend. Overflow occurs when two numbers with the same sign produce a result with opposite sign. The range for n-bit two's complement is -2^(n-1) to 2^(n-1)-1.

Free for IGCSE students

Lock in Data representation: two's complement (representation of negative numbers and subtraction) with real exam questions.

Free instantly-marked CIE IGCSE Computer Science practice — 45 questions a day, no card required.

Try a question →See practice bank