Range of Integers Representable by -bit Two’s Complement
In an -bit two’s complement representation, the most significant bit (MSB) acts as the sign bit, and there are distinct bit patterns total. The set of representable signed integers is:
- Minimum:
- Maximum:
So the representable range is
Key ideas:
- Two’s complement encodes negatives using modular arithmetic on .
- MSB (most significant bit) determines whether a bit pattern is interpreted as nonnegative or negative.
- Sign extension preserves the numeric value.
Note: The range formula above is the standard result for two’s complement encodings, widely used in computer architecture and digital logic.
Two's Complement Representation and Range
Deriving the range (conceptual proof)
Let bits be , where is the MSB. Two’s complement interprets the bit string as a signed value via a weighted sum:
From this:
- If (nonnegative), then the sum is maximized when all remaining bits are 1:
- If (negative), the most negative value occurs when all remaining bits are 0:
Therefore:
Key terms:
- [Modular arithmetic]{def="Working with integers modulo a fixed value such as "} explains why bit patterns wrap around.
- Integer encoding clarifies “representation range.”
- Bit pattern.
Quick check for $n$-bit two’s complement
Compute and . If you ever get a symmetric range around 0, re-check: two’s complement has one extra negative value.
Common mistake: assuming $[-2^{n-1}, 2^{n-1}]$
Two’s complement does not represent . The maximum is , while the minimum is .
Compute the representable integer range for $n$-bit two’s complement
- 1Step 1
Start with and .
- 2Step 2
Express the range as
- 3Step 3
For :
- 4Step 4
Confirm the MSB indicates sign; use sign extension if you change bit-width.
Examples for intuition
(4-bit two’s complement)
- Minimum:
- Maximum:
So the range is:
(8-bit two’s complement, common in bytes)
- Minimum:
- Maximum:
So the range is:
How the range emerges as you increase bit-width
Very small width
n = 2Range: to ."
Wider signed range
n = 4Range: to ."
Byte-sized integers
n = 8Range: to ."
Closed-form solution
General nAlways: ."
Representable range endpoints for selected n
Minimum is ; maximum is .
FAQs and edge cases
Two’s complement range quick recall
Knowledge Check
For -bit two’s complement, which pair correctly gives the minimum and maximum representable integers?