1.3.3 Signed Values with Two’s Complement
A mountain weather station needs to record temperatures both above and below zero. An unsigned binary representation cannot represent a negative value, so the system needs an agreed way to interpret some 8-bit patterns as negative integers.
Two’s complement provides this signed representation. The same eight bit positions can represent values from −128 to 127, and ordinary binary addition circuitry can still be used to process many signed calculations.
By the end of this section, you should be able to:
- distinguish unsigned and signed interpretations of an 8-bit pattern;
- state the range of an 8-bit two’s-complement integer;
- represent positive denary integers using 8-bit two’s complement;
- convert negative denary integers into 8-bit two’s complement;
- convert positive and negative two’s-complement patterns into denary;
- use either sign-changing or negative-place-value methods when decoding;
- explain why the bit width must remain fixed throughout a conversion.
The same bits can have different meanings
An 8-bit pattern does not automatically tell us whether it represents an unsigned value or a signed value. The interpretation being used must be known.
Signed integer 有符号整数: a whole number representation that can include positive and negative values.
Two’s complement 二进制补码: a method of representing signed integers using a fixed number of bits.
| Bit pattern | Unsigned interpretation | 8-bit two’s-complement interpretation |
|---|---|---|
| 00110110 | 54 | 54 |
| 01111111 | 127 | 127 |
| 11100110 | 230 | −26 |
| 11111111 | 255 | −1 |
Common mistake
Do not convert every 8-bit pattern as though it were unsigned. For example, 11100110 represents 230 when unsigned but −26 when interpreted as an 8-bit two’s-complement integer.
The range of an 8-bit signed value
Eight bits provide 256 different patterns. In two’s complement, these patterns are divided between negative and non-negative integers.
| Representation | Minimum value | Maximum value | Total values |
|---|---|---|---|
| 8-bit unsigned | 0 | 255 | 256 |
| 8-bit two’s complement | −128 | 127 | 256 |
Most significant bit 最高有效位: the leftmost bit. In an 8-bit two’s-complement value, it helps determine whether the value is non-negative or negative.
A pattern beginning with 0 represents a value from 0 to 127. A pattern beginning with 1 represents a value from −128 to −1.
The first bit is not a separate minus sign
A leading 1 indicates a negative two’s-complement value, but it is also part of the value itself. It should not simply be removed and replaced with a minus sign.
Representing positive values
Positive two’s-complement values use the same place values as ordinary positive binary, but the most significant bit must be 0.
To represent +73:
- convert 73 into binary;
- keep the representation at exactly eight bits;
- check that the most significant bit is 0.
+73 = 01001001
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Bit | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 |
| Contribution | 0 | 64 | 0 | 0 | 8 | 0 | 0 | 1 |
64 + 8 + 1 = 73
Common mistake
A value such as 200 cannot be represented as a positive 8-bit two’s-complement integer. The positive range stops at 127.
Representing a negative value
To represent a negative value, first create an 8-bit pattern for its positive magnitude. Then change every bit and add 1.
Invert 反转: change every 0 to 1 and every 1 to 0.
One’s complement 反码: the pattern produced by inverting every bit.
Two’s complement 补码: the inverted pattern plus 1.
Find the positive magnitude.
Include all leading zeros.
Swap every 0 and 1.
The result represents the negative value.
Answer-building tip
Keep eight bit positions visible at every stage. Leading zeros are necessary because they become leading ones after inversion.
Worked example: represent −46
A temperature correction of −46 must be stored in an 8-bit two’s-complement register.
Step 1: write the magnitude using eight bits
46 = 00101110
Step 2: invert every bit
00101110 → 11010001
Step 3: add 1
11010001
+ 00000001
----------
11010010
Step 4: state the final representation
−46 = 11010010
Common mistake
Stopping after inversion gives the one’s-complement pattern 11010001. You must still add 1 to produce the two’s-complement representation.
Reading a non-negative pattern
When the most significant bit is 0, use ordinary positive binary place values.
Convert 01011100 into denary:
| Selected place value | Contribution |
|---|---|
| 64 | 64 |
| 16 | 16 |
| 8 | 8 |
| 4 | 4 |
64 + 16 + 8 + 4 = 92
Therefore, 01011100 represents +92.
Reading a negative pattern: change the sign
If the most significant bit is 1, one method is to apply the two’s-complement operation again. This finds the positive magnitude.
Convert 11000101 into denary.
Step 1: identify that the value is negative
The most significant bit is 1, so this is a negative 8-bit two’s-complement value.
Step 2: invert every bit
11000101 → 00111010
Step 3: add 1
00111010 + 1 = 00111011
Step 4: convert the magnitude
00111011 = 32 + 16 + 8 + 2 + 1 = 59
Step 5: restore the negative sign
11000101 represents −59
Show why the result is negative
State that the original most significant bit was 1 before giving the negative denary answer.
Reading a negative pattern: use a negative place value
A second method treats the most significant place value as −128. The remaining columns retain their ordinary positive values.
| Place value | −128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Bit in 11000101 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 |
| Contribution | −128 | 64 | 0 | 0 | 0 | 4 | 0 | 1 |
−128 + 64 + 4 + 1 = −59
Both decoding methods give the same result. Students may use whichever method they can apply reliably.
Common mistake
In the negative-place-value method, only the most significant column is negative. The other place values remain 64, 32, 16, 8, 4, 2 and 1.
Important patterns to recognise
| 8-bit pattern | Two’s-complement value | Reason it is useful |
|---|---|---|
| 00000000 | 0 | There is one representation of zero |
| 00000001 | 1 | Smallest positive integer |
| 01111111 | 127 | Largest positive 8-bit signed value |
| 11111111 | −1 | All bits are 1 |
| 10000000 | −128 | Smallest 8-bit signed value |
The range is not balanced around zero. It includes −128 but does not include +128. This happens because zero occupies one of the non-negative patterns.
Special case: −128
The pattern 10000000 represents −128. Its positive counterpart, +128, is outside the 8-bit signed range.
Why two’s complement is useful
Two’s complement allows positive and negative values to be added using the same column-addition process introduced in the previous lesson.
For example, calculate 34 + (−19).
| Value | 8-bit representation |
|---|---|
| +34 | 00100010 |
| −19 | 11101101 |
00100010
+ 11101101
----------
1 00001111
The carry beyond the fixed eight-bit width is discarded. The stored result is 00001111, which represents 15.
34 + (−19) = 15
Common mistakes and misconceptions
- Treating the most significant bit as a detachable minus sign.
- Using the unsigned range 0 to 255 for a signed 8-bit value.
- Removing leading zeros before inverting the bits.
- Inverting the bits but forgetting to add 1.
- Adding 1 before inverting instead of after.
- Converting a negative pattern as ordinary unsigned binary.
- Using +128 as an allowed positive 8-bit signed value.
- Using −127 as the minimum and forgetting that −128 is representable.
- Changing the number of bits during the calculation.
Interactive: Two’s Complement Laboratory
Convert between signed denary integers and 8-bit two’s-complement patterns. The laboratory shows the magnitude, inversion and add-one stages and can animate the process.
Keep a reliable routine
For a negative denary value: write eight bits → invert every bit → add 1. For a negative binary pattern, applying the same operation reveals its magnitude.
Practice
Core questions
- Define the term signed integer.
- State the range of an 8-bit two’s-complement integer.
- Represent +58 using 8-bit two’s complement.
- Represent −37 using 8-bit two’s complement.
- Represent −74 using 8-bit two’s complement.
- Convert 01011100 from 8-bit two’s complement to denary.
- Convert 11101001 from 8-bit two’s complement to denary.
- Convert 10011010 from 8-bit two’s complement to denary.
-
State the two’s-complement meanings of:
- 01111111;
- 10000000;
- 11111111.
- Explain why 11110100 can represent either 244 or −12.
- Explain why leading zeros must be retained while converting a negative value.
- Explain why inversion alone does not produce a two’s-complement value.
- Use the negative-place-value method to convert 10110110 into denary.
- Add +27 and −11 using their 8-bit two’s-complement patterns.
Extension questions
- Explain why an 8-bit two’s-complement representation includes −128 but not +128.
- Find the two’s complement of 10100110 and explain how this changes the sign of the value.
- Explain why applying the two’s-complement operation twice returns the original pattern for values other than the special boundary case.
- Explain why 00000000 is the only representation of zero in two’s complement.
- A program expects signed 8-bit data but receives the pattern 11011000 from an unsigned sensor. Explain why the value may be interpreted incorrectly.
- Explain why the bit width must be known before a two’s-complement value can be interpreted.
Check selected answers
- The 8-bit two’s-complement range is −128 to 127.
- +58 is 00111010.
- −37 is 11011011.
- −74 is 10110110.
- 01011100 represents 92.
- 11101001 represents −23.
- 10011010 represents −102.
- 01111111 is 127, 10000000 is −128 and 11111111 is −1.
- 10110110 is −128 + 32 + 16 + 4 + 2 = −74.
- +27 is 00011011. −11 is 11110101. Their 8-bit sum is 00010000, which represents 16.
Review
Key ideas
- Unsigned and signed interpretations can give the same pattern different meanings.
- An 8-bit two’s-complement integer ranges from −128 to 127.
- A most significant bit of 0 represents a non-negative value.
- A most significant bit of 1 represents a negative value.
- Positive values are written as ordinary binary using eight bits.
- To encode a negative value, write its magnitude, invert all bits and add 1.
- A negative pattern can be decoded by taking its two’s complement again.
- A negative pattern can also be decoded using the −128 place value.
- Two’s complement has one representation of zero.
- The required bit width must remain fixed throughout a conversion.
Quick self-check
- Can I state the 8-bit signed range?
- Can I encode a positive signed value?
- Can I encode a negative signed value?
- Can I decode a positive pattern?
- Can I decode a negative pattern in two ways?
- Can I explain why leading zeros matter?
- Can I distinguish unsigned and signed interpretations?
One-minute exit task
Convert −53 into 8-bit two’s complement. Then use either decoding method to check your answer.