Lesson overview
Reason about fixed-width integer storage and overflow.
Starter: make the model explicit
Before reading the worked example, write down the objects involved, the claim being made and the notation you expect to use. This prevents the common error of calculating before modelling.
Learning objectives
- Explain why fixed-width storage has a limited range.
- Interpret simple unsigned and two's complement bit patterns.
- Predict overflow in a small integer example.
Learning outcomes
- By the end of this lesson, you can explain why fixed-width storage has a limited range.
- By the end of this lesson, you can interpret simple unsigned and two's complement bit patterns.
- By the end of this lesson, you can predict overflow in a small integer example.
Key vocabulary
What this lesson is about
Integer representation is about how whole numbers are stored using a fixed number of bits. Unsigned representation uses every bit pattern for non-negative values, so 8 bits can represent 0 to 255.
Two's complement is the standard signed-integer representation used by most modern processors. In an n-bit two's complement value, the leftmost bit has negative weight −2ⁿ⁻¹; the other bits keep their usual positive powers of two. That is why 11111111 is −1 in 8-bit two's complement, not 255.
Overflow occurs because fixed-width storage has a finite range. The mathematical answer may exist, but the machine representation may not have enough bits to store it.
Terms, acronyms and named methods
These are the phrases and named techniques used in this lesson. Read this section before the worked example so the notation and examples have a clear meaning.
Formal notation and definitions
How to read the symbols
Use the range formula and bit weights to decode the pattern before doing arithmetic. In two's complement, the leftmost bit contributes a negative value, so 1000 in 4 bits is −8 and 1111 is −1.
Degree-level reasoning
Representation topics ask you to distinguish mathematical value from machine encoding. The same bit pattern can mean different things under different interpretation rules.
Degree-level answers should mention range, precision, rounding or overflow where those limits affect correctness.
Do not stop at a correct-looking answer. State why the method is valid, whether the result depends on a hidden assumption, and what would count as a counterexample.
Worked formal model
This section shows the model, notation, calculation and interpretation as one worked answer. The notation is part of the reasoning, not decoration.
1. Context and objects
In 4-bit two's complement, 1111 represents -1 because the leftmost bit has weight -8 while the remaining bits have weights 4, 2 and 1.
Objects: the bit width n, the bit pattern, the interpretation rule, and the representable range.
Model cue: Use two 4-bit number wheels: unsigned runs from 0 to 15, while two's complement runs from -8 to 7. The same bit pattern can therefore mean different values depending on interpretation.
2. Mathematical working
Plain text version
4-bit two's complement weights: -8, 4, 2, 1 1111 = -8 + 4 + 2 + 1 = -1 0111 + 0001 = 1000, but 1000 = -8, so the intended result 8 overflowed
3. How to read the working
- Fix the bit width before interpreting the pattern.
- For unsigned integers, all bit weights are positive.
- For two's complement, the leftmost bit has negative weight.
- Overflow occurs when the intended mathematical result is outside the representable range.
4. Computing meaning and check
The bit pattern has meaning only after an interpretation rule is chosen. Overflow is a representational failure: the mathematical value exists, but the fixed-width encoding cannot hold it.
Now check: For 5-bit two's complement, state the range, decode 11111, and explain whether 01111 + 00001 overflows.
Worked example
From scenario to formal reasoning
Scenario: In 4-bit two's complement, 1111 represents -1 because the leftmost bit has weight -8 while the remaining bits have weights 4, 2 and 1.
Method: Use the definitions and notation introduced above, then state what the result means in this computing scenario.
Reveal model answer
Decode 4-bit two's complement 1111 by using weights -8, 4, 2 and 1. The value is -8 + 4 + 2 + 1 = -1. Decode 1000 as -8 + 0 + 0 + 0 = -8. Adding 0111 and 0001 gives 1000; the bit pattern is valid, but as a signed 4-bit result it means -8, so the intended mathematical sum 8 has overflowed.
Worked solution structure
How a strong answer should be written
- Define: State the domain and the objects under discussion. For this lesson, begin from For n unsigned bits, values range from 0 to 2ⁿ − 1.
- Apply: Use the relevant definition from number representation; do not rely on the diagram, wording or intuition alone.
- Check: Test a boundary case, counterexample candidate or representation limit.
- Conclude: Write one sentence that connects the formal result back to the computing scenario.
Common misconception
A common mistake is assuming mathematical integers and machine integers behave identically. Machine integers are bounded representations, and the same bit pattern can mean different values under unsigned and two's complement interpretation.
Guided practice
- State the range of 5-bit two's complement and decode 11111 using bit weights.
- Add 01111 and 00001 in 5-bit two's complement and explain the overflow.
- Decode the same 4-bit pattern 1111 as unsigned and as two's complement.
- Write one sentence explaining why fixed-width machine integers are not the same model as mathematical integers.
Quick checks
1. What is the 5-bit two's complement range?
2. In 5-bit two's complement, 01111 + 00001 overflows because:
Digital exam practice
Example exam task
For 5-bit two's complement, state the range, decode 11111, and decide whether 01111 + 00001 overflows. Explain the fixed-width representation issue.
Notation toolkit
Means: a fixed number of bits is available
How to use: Use it before deciding the representable range.
Means: the n-bit two's complement range
How to use: Use it to test whether a signed result can be stored.
Means: a leading 1 carries negative weight in two's complement
How to use: Use it when decoding signed bit patterns.
What a good answer is expected to show
A strong answer for this lesson defines the bit width n, the bit pattern, the interpretation rule, and the representable range, applies the number representation method with visible working, and finishes by interpreting the result in the computing scenario.
How to solve it
- Fix the bit width before interpreting the pattern.
- For unsigned integers, all bit weights are positive.
- For two's complement, the leftmost bit has negative weight.
- Overflow occurs when the intended mathematical result is outside the representable range.
Model answer
Reveal model answer
With 5-bit two's complement, the range is -16 to 15. The pattern 11111 has value -16 + 8 + 4 + 2 + 1 = -1. The sum 01111 + 00001 represents 15 + 1 = 16, which is outside the range, so the stored 5-bit result overflows to 10000, interpreted as -16.
Practise next
- State the range of 5-bit two's complement and decode 11111 using bit weights.
- Add 01111 and 00001 in 5-bit two's complement and explain the overflow.
Self-marking criteria
- Gives the range -16 to 15.
- Decodes 11111 as -1 using weights.
- Identifies 15 + 1 as outside range.
- Explains why the stored bit pattern wraps to a negative value.
- Distinguishes mathematical integers from machine integers.
Extension
Change one assumption in the worked scenario and decide whether the same method still applies. If it does not, name the exact point where the reasoning breaks.
Study route
Save one clean worked answer from this lesson. Include the problem statement, notation, working, final answer and a short note explaining the computing meaning of the result.
Next lesson: Floating Point Representation and Approximation Error.
