Two’s Complement Range Calculator
Calculate the exact minimum and maximum value for any n-bit two’s-complement signed integer. Inspect sign-bit weight, negative and nonnegative capacity, boundary binary patterns, hexadecimal limits, and standard or custom integer widths.
What Is a Two’s Complement Range?
The two’s-complement range is the complete set of signed integer values that can be represented by a fixed number of binary bits using two’s-complement encoding.
Two’s complement is the dominant signed integer representation used by modern processors and programming environments. It allows positive, negative, and zero values to share one compact binary encoding without requiring a separate sign-and-magnitude format.
For an n-bit value, the smallest representable number is −2n−1, while the largest is 2n−1 − 1.
Two’s Complement Range Formula
Half of all available bit patterns correspond to negative values. The other half represent zero and positive values.
Why the Most Significant Bit Has Negative Weight
In ordinary unsigned binary, each bit has a positive positional weight. Two’s-complement encoding changes the interpretation of the most significant bit.
For an n-bit two’s-complement number, the highest bit has weight −2n−1. The remaining bits retain their normal positive binary weights.
This negative high-order weight is what allows the same binary addition hardware to work naturally with both positive and negative signed values.
How to Calculate a Two’s-Complement Range
Common Two’s-Complement Ranges
| Bits | Minimum | Maximum | Total patterns |
|---|---|---|---|
| 4 | -8 | 7 | 16 |
| 8 | -128 | 127 | 256 |
| 16 | -32,768 | 32,767 | 65,536 |
| 32 | -2,147,483,648 | 2,147,483,647 | 4,294,967,296 |
| 64 | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 | 18,446,744,073,709,551,616 |
8-Bit Two’s-Complement Range
Minimum and Maximum Binary Patterns
The minimum two’s-complement value always begins with 1 and contains zeros in every lower bit position. The maximum begins with 0 and contains ones in every remaining position.
| Width | Minimum pattern | Maximum pattern |
|---|---|---|
| 4-bit | 1000 |
0111 |
| 8-bit | 10000000 |
01111111 |
| 16-bit | 1000000000000000 |
0111111111111111 |
| 32-bit | 10000000000000000000000000000000 |
01111111111111111111111111111111 |
Why Two’s Complement Has One Extra Negative Value
Two’s-complement ranges are slightly asymmetric. An 8-bit value ranges from −128 to +127 rather than −127 to +127.
There are 256 total bit patterns. Exactly 128 begin with 1 and correspond to negative values. The 128 patterns beginning with 0 represent zero through 127.
Two’s-Complement Range vs Unsigned Range
Uses the range −2^(n−1) through 2^(n−1)−1 and includes negative values.
Uses every bit for magnitude and ranges from 0 through 2^n−1.
Two’s-Complement Range Limits in Hexadecimal
Hexadecimal makes two’s-complement boundaries easier to read because one hex digit represents exactly four binary bits.
| Width | Minimum pattern | Maximum pattern |
|---|---|---|
| 8-bit | 80 |
7F |
| 16-bit | 8000 |
7FFF |
| 32-bit | 80000000 |
7FFFFFFF |
| 64-bit | 8000000000000000 |
7FFFFFFFFFFFFFFF |
Two’s-Complement Ranges for Nonstandard Bit Widths
Two’s complement is not limited to 8, 16, 32, or 64 bits. Packed protocols, DSP data, sensors, ADC output, instruction formats, and embedded registers often use custom widths.
| Bits | Minimum | Maximum |
|---|---|---|
| 3 | -4 | 3 |
| 5 | -16 | 15 |
| 10 | -512 | 511 |
| 12 | -2,048 | 2,047 |
| 24 | -8,388,608 | 8,388,607 |
Two’s-Complement Overflow at the Range Boundaries
A fixed-width two’s-complement value cannot directly represent numbers outside its valid range. Arithmetic that crosses the minimum or maximum boundary may overflow.
For example, an 8-bit signed value cannot directly represent 128. Likewise, −129 is below the minimum representable int8 value.
Where a Two’s-Complement Range Calculator Is Useful
Sensor values
A 12-bit signed sensor field has a valid two’s-complement range of −2048 through 2047. Knowing that limit helps identify invalid readings or incorrect decoding.
Instruction formats
Immediate values and relative offsets often use signed fields with nonstandard widths. Their minimum and maximum values follow the same two’s-complement formula.
Binary parsers
Range calculations are useful when validating decoded values from files, packets, firmware, telemetry, and custom binary structures.
Two’s-Complement Range Mistakes to Avoid
Using −(2^n) as the minimum
The minimum signed value is −2^(n−1), not −2^n.
Using 2^(n−1) as the maximum
The maximum is one less: 2^(n−1)−1.
Treating the range as symmetric
Two’s complement includes one more negative value than strictly positive values.
Confusing a raw bit pattern with its unsigned value
For example, hexadecimal FF is 255 when unsigned but −1 when interpreted as an 8-bit two’s-complement value.
Two’s Complement Range Calculator FAQs
Common questions about two’s-complement limits, sign bits, minimum and maximum values, bit widths, hexadecimal boundaries, and overflow.