# Two's Complement Signed Integers

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 1: Data Representation
- **Estimated Duration:** 15 minutes
- **Access:** Open Theory + Free Practice

---

## Theory & Conceptual Background

Two's complement is the universal method used by digital computers to represent both positive and negative integers in binary.

Learning Objectives
Understand the concept and need for two's complement signed representation.Convert between denary integers and 8-bit two's complement binary across the range $-128$ to $+127$.Explain the engineering advantages of two's complement over sign-and-magnitude representation.

Core Syllabus Theory
1. Why Two's Complement is Needed
Unsigned binary representation can only store positive integers (e.g. 8 bits represent $0$ to $255$). Computer processors require a reliable system to represent negative numbers as well.
An older approach called sign-and-magnitude used the leftmost bit as a sign indicator ($0 = +, 1 = -$). However, sign-and-magnitude has two major design flaws:
Two representations for zero: $+0$ ($00000000$) and $-0$ ($10000000$), wasting code space and complicating logic equality comparisons.Complex hardware: Standard binary addition hardware fails when adding negative numbers; dedicated subtraction circuitry is required.
Two's complement solves both problems:
There is only one representation of zero ($00000000$).Subtraction can be performed using standard addition circuitry: $A - B = A + (-B)$.

2. Positional Place Values for 8-Bit Two's Complement
In an 8-bit two's complement register, the Most Significant Bit (MSB) carries a negative weight of $-128$. All other positions carry positive binary weights:
$$\begin{array}{|c|c|c|c|c|c|c|c|}
\hline
\mathbf{-128} & \mathbf{+64} & \mathbf{+32} & \mathbf{+16} & \mathbf{+8} & \mathbf{+4} & \mathbf{+2} & \mathbf{+1} \\
\hline
\end{array}$$
Positive integers (MSB = 0): Range from $00000000_2 \ (0_{10})$ to $01111111_2 \ (+127_{10})$.Negative integers (MSB = 1): Range from $11111111_2 \ (-1_{10})$ down to $10000000_2 \ (-128_{10})$.Total range: $-128$ to $+127$ ($256$ distinct values).

3. Converting Negative Denary to 8-Bit Two's Complement
To convert a negative denary number (e.g. $-38$) to 8-bit two's complement, follow the Invert and Add 1 algorithm:
Step 1: Write the positive binary number in full 8 bits:
$$+38_{10} = 00100110_2$$
Step 2: Invert all bits ($0 \to 1$ and $1 \to 0$) to obtain One's Complement:
$$\text{Inverted: } 11011001_2$$
Step 3: Add 1 to the inverted binary string:
$$\begin{array}{rc}
     & 11011001 \\
   + & 00000001 \\
   \hline
     & 11011010_2
   \end{array}$$
$$\text{Result: } -38_{10} = 11011010_2$$

4. Converting Two's Complement Binary to Denary
Method A: Direct Positional Place Value Addition
Evaluate $11110100_2$:
$$\text{Value} = (-128 \times 1) + (64 \times 1) + (32 \times 1) + (16 \times 1) + (8 \times 0) + (4 \times 1) + (2 \times 0) + (1 \times 0)$$
$$\text{Value} = -128 + 64 + 32 + 16 + 4 = -12_{10}$$
Method B: Invert and Add 1 (Magnitude Retrieval)
Invert $11110100 \to 00001011$.Add $1$: $00001011 + 1 = 00001100_2 = 12_{10}$.Attach the negative sign: $-12_{10}$.

Exam Tips & Common Pitfalls

  Note: Always Write 8 Full Bits: When converting positive numbers, never omit leading zeros before inverting. Inverting $100110$ is completely wrong; you must invert the full 8-bit representation $00100110$.
Checking Negative One: $-1$ in two's complement is always represented by all 1s ($11111111_2$).

Key Terminology Glossary
Two's Complement: A method of encoding signed integers where the MSB has a negative place value.One's Complement: The intermediate binary value obtained by inverting all bits of a binary number.Sign Bit: The leftmost bit (MSB), where 0 indicates positive and 1 indicates negative.
Written practice and self-review
Explain two distinct reasons why computer processors use two's complement representation rather than sign-and-magnitude representation to store signed integers in hardware.
Write an explanation before checking the theory. Check that each claim answers the question, uses the correct concept and explains why it applies. Discuss uncertain points with a teacher. The structured exercise below checks specific facts; it does not automatically mark this explanation.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: Two's Complement Range (Multiple choice, 25 XP)

**Instructions:**
What is the range of integers that can be represented using 8-bit Two's Complement?

**Options:**
- **A**: 0 to +255
- **B**: -127 to +128
- **C**: -256 to +255
- **D**: -128 to +127



### Exercise 2: Exam-Style Question: Two's Complement Conversions (Fill in blank, 35 XP)

**Instructions:**
Convert the following values using 8-bit two's complement representation:


**Starter Code:**
```text
{"prompt":"1. Represent denary -38 as an 8-bit two\u0027s complement binary number.\n2. Convert 8-bit two\u0027s complement 11110100 to denary.\n3. Convert 8-bit two\u0027s complement 01001100 to denary.","template":"1. Denary -38 in two\u0027s complement: [Blank 1]\n2. Denary value of 11110100: [Blank 2]\n3. Denary value of 01001100: [Blank 3]","word_bank":["11011010","-12","76","11011001","-24","140"],"blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}]}
```


### Exercise 3: Application: Check the reasoning (Fill in blank, 30 XP)

**Instructions:**
Work out each answer before submitting. Eight-bit two's complement for -19: Denary value of signed 11110111: Lowest eight-bit two's complement value:


**Starter Code:**
```text
{"prompt":"Application: Check the reasoning","template":"1. Eight-bit two's complement for -19: [blank_1]\n2. Denary value of signed 11110111: [blank_2]\n3. Lowest eight-bit two's complement value: [blank_3]","blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}],"word_bank":["11101101","-9","-128","11101100","10010011","247","-8","-127","127"]}
```


