Signed binary using two’s complement — AQA A-Level Computer Science
Two's complement is a mathematical system used in computer systems to represent signed integers in binary, where the most significant bit holds a negative place value. It simplifies processor design by allowing binary addition and subtraction to be executed using identical arithmetic logic circuits without requiring separate hardware.
Signed binary using two’s complement explained
Signed binary in two's complement uses the leftmost bit as a sign bit, which has a place value of negative 2 to the power of (n minus 1), where n is the number of bits.
Read the full explanation
For an 8-bit pattern, the leftmost bit is worth −128, and each remaining bit is worth its usual positive power of two: 64, 32, 16, 8, 4, 2 and 1. To convert 11110110 to decimal, add the place values of the set bits: −128 + 64 + 32 + 16 + 4 + 2 = −10. To convert in the other direction, write the positive value in binary, invert every bit, and add 1 to obtain the two's complement pattern; for example, +10 is 00001010, inverting gives 11110101, and adding 1 gives 11110110. Always state the bit length first, because the same pattern means a different value in a different number of bits. Check the answer by confirming that the sign bit agrees with the sign of the result.
Your focus
- Students are expected to be able to convert between signed binary and decimal and vice versa.
Which command word is this?
Show all intermediate numerical steps, including bit padding, inversion, addition of 1, and the final binary or denary answer.
Signed binary using two’s complement exam tips
Topic Overview
Two's complement is the standard binary representation for signed integers in digital computing, mandated by the AQA A-Level Computer Science specification. It assigns a negative place value to the most significant bit (MSB), enabling both positive and negative values to be stored uniformly within fixed-width registers.
Understanding two's complement is crucial because it allows the Arithmetic Logic Unit (ALU) to perform subtraction via standard adder circuitry, avoiding duplicate hardware for negative numbers. This concept also underpins fixed-point and floating-point representations, binary arithmetic operations, and processor status flags.
Key Concepts
- →The Most Significant Bit (MSB) acts as a negative place-value weight equal to -(2^(n-1)) rather than simply a sign flag.
- →Conversion from positive to negative is achieved by finding the one's complement (inverting all bits) and adding 1, or scanning from right to left, keeping bits unchanged up to and including the first '1', then inverting the rest.
- →An n-bit system represents values in the asymmetric range -(2^(n-1)) to +(2^(n-1) - 1), which uniquely represents zero and avoids the '+0' and '-0' ambiguity of sign and magnitude.
- →Subtraction (A - B) is implemented in hardware as addition: A + (-B), discarding any carry-out bit beyond the register width.
Marking Points
- Identifies the leftmost bit as the sign bit with a negative place value.
- Calculates the negative place value as −2^(n−1) for the stated bit length.
- Adds the positive place values of the remaining set bits correctly.
- Inverts all bits and adds 1 when converting a negative decimal value to two's complement.
- Confirms the bit length before interpreting or producing the pattern.
Examiner Tips
- 💡Write the place values above the bits before adding, so the negative sign bit is not overlooked.
- 💡Check the answer by testing whether the sign bit matches the sign of the decimal result.
- 💡When asked to convert a negative denary value, write the positive binary first, then invert and add 1 as a separate visible step.
- 💡Always check whether the exam question specifies an 8-bit, 12-bit, or 16-bit register; failing to pad with leading zeros before negating loses all method marks.
- 💡When explaining why two's complement is preferred over sign and magnitude, explicitly mention both the absence of duplicate representations of zero and the simplification of ALU circuitry.
- 💡Verify negative conversions quickly in your head by evaluating: MSB weight + sum of remaining positive bits.
Common Mistakes
- Treats the leftmost bit as a positive place value; the sign bit must carry a negative value such as −128 in an 8-bit pattern.
- Adds 1 before inverting the bits when forming the two's complement of a negative number, which gives the wrong pattern.
- Interprets a pattern without reference to its bit length, so the same bits are read with the wrong sign or magnitude.
- Believing that two's complement has two representations for zero: unlike sign and magnitude, two's complement features only a single zero (e.g., 00000000 in 8 bits).
- Assuming that an extra carry bit generated past the MSB indicates an arithmetic overflow; this bit is normal and discarded in two's complement addition/subtraction.
- Forgetting to pad numbers to the required register size before taking the two's complement, which produces completely incorrect sign and value bits.
Revision Plan
- 1Day 1: Master the conversion of positive denary values to two's complement binary for 8-bit and 16-bit widths using both inversion methods.
- 2Day 2: Practise converting negative binary patterns back to denary using negative MSB place values.
- 3Day 3: Perform subtraction operations by negating the subtrahend and executing binary addition, monitoring for true overflow.
- 4Day 4: Work through AQA past paper questions focusing on algebraic range expressions and comparison with sign and magnitude.
Exam Question Types
- 📋Denary to binary conversion: Converting a negative denary integer into an 8-bit or 12-bit two's complement pattern.
- 📋Binary arithmetic and subtraction: Adding or subtracting two signed binary values with an explanation of carry and overflow flags.
- 📋Theoretical comparison: Short-answer questions explaining why modern processors use two's complement over alternative signed representations.
- 📋Range determination: Calculating maximum and minimum representable values for a given register size n.
Command Word Expectations (AQA)
Show all intermediate numerical steps, including bit padding, inversion, addition of 1, and the final binary or denary answer.
Set out the mathematical or structural reasoning behind a concept, such as why a particular hardware advantage arises from two's complement.
Give a concise, direct fact or value (such as a range boundary or binary bit pattern) without needing extended working.
How Students Lose Marks (Examiner Pitfalls)
Step-by-Step Worked Solutions
Question: Using 8-bit two's complement arithmetic, calculate the result of the denary operation 42 - 75. Show all your working, including the conversion of negative numbers and the binary addition.
- 1.Step 1: Convert +42 to an 8-bit binary pattern: 32 + 8 + 2 = 00101010.
- 2.Step 2: Convert +75 to an 8-bit binary pattern: 64 + 8 + 2 + 1 = 01001011.
- 3.Step 3: Negate +75 to find -75 using two's complement: invert the bits of 01001011 to get 10110100, then add 1 to yield 10110101.
- 4.Step 4: Perform binary addition of 42 (00101010) and -75 (10110101): 00101010 + 10110101 = 11011111.
- 5.Step 5: Verify using column weights (-128, 64, 32, 16, 8, 4, 2, 1): -128 + 64 + 0 + 16 + 8 + 4 + 2 + 1 = -33. Since 42 - 75 = -33, the binary sum is correct.
Question: State the minimum and maximum denary values that can be represented using an n-bit signed integer in two's complement. Hence, calculate the range for a 12-bit register.
- 1.Step 1: State the general algebraic formula for the range of an n-bit two's complement integer: Minimum = -(2^(n-1)), Maximum = (2^(n-1)) - 1.
- 2.Step 2: Substitute n = 12 into the lower bound: -(2^(12-1)) = -(2^11) = -2048.
- 3.Step 3: Substitute n = 12 into the upper bound: (2^(12-1)) - 1 = (2^11) - 1 = 2048 - 1 = +2047.
- 4.Step 4: Formulate the continuous integer range.