Two's complement signed integers (Edexcel GCSE Computer Science): Revision Notes
Two's complement signed integers
What is two's complement?
Two's complement is a clever method that computers use to represent both positive and negative numbers in binary. This system allows computers to store signed integers (numbers that can be positive or negative) using the same amount of memory space.
The key to understanding two's complement is the Most Significant Bit (MSB) - this is the leftmost bit in your binary number:
- If the MSB is 0, the number is positive
- If the MSB is 1, the number is negative
Think of the MSB as a sign indicator that tells you whether you're dealing with a positive or negative value. This single bit determines the entire interpretation of your binary number!
Converting positive numbers to negative using two's complement
When you need to represent a negative number in two's complement, follow this simple three-step process:
Two's Complement Algorithm:
- Start with the positive version - Write out the positive number in binary
- Flip all the bits - Change every 0 to 1, and every 1 to 0 (this creates what's called the one's complement)
- Add 1 - Add binary 1 to your result
Let's see this in action with a worked example:
Worked Example: Converting +21 to -21
Starting with +21 in 8-bit binary: 00010101
Step 1: Start with positive binary
00010101 = +21
Step 2: Flip all bits (one's complement)
00010101 → 11101010
Step 3: Add 1
11101010 + 00000001 = 11101011
Result: 11101011 represents -21 in two's complement
This demonstrates how to convert +21 into -21 using two's complement. Starting with the binary representation of +21 (00010101), we flip all the bits to get 11101010, then add 1 to get the final result of 11101011, which represents -21.
Converting two's complement back to positive
To convert a negative two's complement number back to its positive equivalent, you use the exact same process! This is what makes two's complement so elegant - the conversion works in both directions.
Here's how to find the decimal value of a two's complement number:
Worked Example: Converting 11001010 to decimal
Given binary number: 11001010
Step 1: Check MSB - it's 1, so this is negative
Step 2: Apply two's complement algorithm
- Flip all bits:
11001010→00110101 - Add 1:
00110101+00000001=00110110
Step 3: Convert to decimal
00110110 = = = 54
Step 4: Apply sign Since original MSB was 1, the answer is -54
Understanding the process step by step
When working with two's complement conversions, it's helpful to organise your work clearly:
Systematic Approach to Two's Complement:
- Identify the sign - Check the MSB first
- Apply the algorithm - Flip bits, add 1
- Convert to decimal - Use place values ()
- Apply the correct sign - Don't forget whether your original number was positive or negative
Exam tips and common mistakes
Critical Exam Tips:
- Always check the MSB first to determine if you're working with a positive or negative number
- When flipping bits, make sure you flip every single bit, not just some of them
- Remember that adding 1 in binary might cause carries - be careful with your arithmetic
- Show your working clearly in exam questions - examiners often award marks for method even if your final answer isn't perfect
- Practice with different bit lengths (4-bit, 8-bit, etc.) as the principle is the same but the numbers change
Remember!
Key Points to Remember:
- MSB = 0 means positive, MSB = 1 means negative - this is your first clue about any two's complement number
- The conversion algorithm works both ways - flip all bits, then add 1, whether you're going from positive to negative or negative to positive
- Two's complement allows computers to use the same circuits for both addition and subtraction, making them more efficient
- Always double-check your bit flipping - this is where most mistakes happen in exams
- Practice makes perfect - the more examples you work through, the more automatic this process becomes