Two’s complement representation

Cambridge IGCSE Computer Science (0478) · lesson 4 of 35 · 25 min

Why Two’s Complement?

Computers need to represent negative numbers. The most widely used method is two’s complement. It has two key advantages over alternatives like sign-and-magnitude:

  • There is only one representation of zero.
  • Addition and subtraction use the same hardware circuit — no special cases needed.

In an 8-bit two’s complement number, the most significant bit (MSB) has a place value of −128 instead of +128. All other bits keep their positive place values.

Range and Place Values

  • Bit 7 (MSB)
  • Bit 6
  • Bit 5
  • Bit 4
  • Bit 3
  • Bit 2
  • Bit 1
  • Bit 0
  • −128
  • 64
  • 32
  • 16
  • 8
  • 4
  • 2
  • 1

8-bit two’s complement range: −128 to +127.

Converting to Two’s Complement

To negate a number using two’s complement:

  • Write the positive binary representation.
  • Invert all bits (flip 0s to 1s and 1s to 0s) — this is the one’s complement.
  • Add 1 to the result.

Worked Examples

Represent −45 in 8-bit two’s complement

Step 1: +45 = 00101101

Step 2: Invert → 11010010

Step 3: Add 1 → 11010011

Verify: −128 + 64 + 16 + 2 + 1 = −128 + 83 = −45 ✓

Subtract using two’s complement: 15 − 6

Convert −6 to two’s complement: 6=00000110 → invert=11111001 → +1=11111010

00001111 (+15)

  • 11111010 (−6 in two’s complement)

──────────

1 00001001 → discard carry → 00001001 = 9 ✓

What is the 8-bit two’s complement of −1?

  • 10000001
  • 11111110
  • 11111111
  • 10000000

Answer: 11111111
1=00000001 → invert=11111110 → +1=11111111.

What is the range of an 8-bit two’s complement number?

  • 0 to 255
  • −127 to 127
  • −128 to 127
  • −128 to 128

Answer: −128 to 127
MSB = −128; max positive = 01111111 = 127.

What is the denary value of two’s complement 10000000?

  • 128
  • −127
  • −128
  • 0

Answer: −128
Only the MSB is set: −128 + 0 = −128.


Previous lesson: Binary addition and overflow
Back to Cambridge IGCSE Computer Science (0478)
Next lesson: Character sets: ASCII and Unicode