Secondary Computer Science / 1.3 Working with Fixed-Width Binary

1.3.3 Signed Values with Two’s Complement

🔒 Lesson slides are available to signed-in users. Sign in

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.

Unsigned integer 无符号整数: a whole number representation that includes zero and positive values only.

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
10000000 −128
11111111 −1
00000000 0
01111111 127
Range 范围: the minimum and maximum values that a representation can store.

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:

  1. convert 73 into binary;
  2. keep the representation at exactly eight bits;
  3. 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.

Magnitude 大小: the size of a number without considering whether it is positive or negative.

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.
1 Ignore the minus temporarily

Find the positive magnitude.

2 Write eight bits

Include all leading zeros.

3 Invert every bit

Swap every 0 and 1.

4 Add 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

Two’s complement is useful because the processor can use the same binary addition process for many calculations involving positive and negative integers.

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.

Interactive investigation

Encode and decode signed 8-bit integers

Current result 11010010 Signed value: −46
1. Choose a conversion
Negative values require the inversion and add-one process.
Select “Animate process” to follow each conversion stage.
Stage 1 Magnitude as eight bits 00101110
Stage 2 Invert every bit 11010001
Stage 3 Add 1 11010010
Result −46 represented 11010010

2. Inspect the bit patterns

Magnitude
Inverted
Final
Most significant bit 1 — negative
Unsigned interpretation 210
Signed interpretation −46
Allowed range −128 to 127
Interpretation The leading 1 indicates a negative value. Inverting and adding 1 gives a magnitude of 46.

Conversion challenge

Encode the signed value

Represent −37 using 8-bit two’s complement.

Keep the representation at eight bits.

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

  1. Define the term signed integer.
  2. State the range of an 8-bit two’s-complement integer.
  3. Represent +58 using 8-bit two’s complement.
  4. Represent −37 using 8-bit two’s complement.
  5. Represent −74 using 8-bit two’s complement.
  6. Convert 01011100 from 8-bit two’s complement to denary.
  7. Convert 11101001 from 8-bit two’s complement to denary.
  8. Convert 10011010 from 8-bit two’s complement to denary.
  9. State the two’s-complement meanings of:
    1. 01111111;
    2. 10000000;
    3. 11111111.
  10. Explain why 11110100 can represent either 244 or −12.
  11. Explain why leading zeros must be retained while converting a negative value.
  12. Explain why inversion alone does not produce a two’s-complement value.
  13. Use the negative-place-value method to convert 10110110 into denary.
  14. Add +27 and −11 using their 8-bit two’s-complement patterns.

Extension questions

  1. Explain why an 8-bit two’s-complement representation includes −128 but not +128.
  2. Find the two’s complement of 10100110 and explain how this changes the sign of the value.
  3. Explain why applying the two’s-complement operation twice returns the original pattern for values other than the special boundary case.
  4. Explain why 00000000 is the only representation of zero in two’s complement.
  5. A program expects signed 8-bit data but receives the pattern 11011000 from an unsigned sensor. Explain why the value may be interpreted incorrectly.
  6. Explain why the bit width must be known before a two’s-complement value can be interpreted.
Check selected answers
  1. The 8-bit two’s-complement range is −128 to 127.
  2. +58 is 00111010.
  3. −37 is 11011011.
  4. −74 is 10110110.
  5. 01011100 represents 92.
  6. 11101001 represents −23.
  7. 10011010 represents −102.
  8. 01111111 is 127, 10000000 is −128 and 11111111 is −1.
  9. 10110110 is −128 + 32 + 16 + 4 + 2 = −74.
  10. +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

  1. Can I state the 8-bit signed range?
  2. Can I encode a positive signed value?
  3. Can I encode a negative signed value?
  4. Can I decode a positive pattern?
  5. Can I decode a negative pattern in two ways?
  6. Can I explain why leading zeros matter?
  7. 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.