Two’s complement is the standard way to represent signed integers in a fixed number of binary bits. It uses the bit pattern itself to encode positive values, zero, and negative values, allowing the same binary adder to handle signed and unsigned-looking bit patterns.
This explanation uses an eight-bit word throughout. The two’s-complement binary method connects each pattern to a signed value through positional weights, then uses ordinary binary addition for arithmetic.
Why does signed binary need two’s complement?
Bits naturally represent nonnegative values: with eight bits, 00000000 through 11111111 represent 0 through 255 when interpreted as unsigned binary. Signed integers need a way to represent values below zero as well as positive values.
A signed encoding must also support one representation of zero and practical addition and subtraction. Two’s complement meets these needs without storing a separate sign-and-magnitude field. Every bit contributes to the value, including the most significant bit (MSB), whose weight is negative rather than positive.
In binary two’s complement, the MSB signals the value range through its weight, but it is not a detachable sign bit attached to an unchanged magnitude. Changing that bit changes the complete numerical interpretation of the pattern.
How does two’s-complement binary encode values?
For an eight-bit word, the positional weights are:
-128, 64, 32, 16, 8, 4, 2, 1
The leftmost bit has weight -128. Each remaining bit has the familiar positive power-of-two weight. Add the weights of the bits set to 1 to decode the signed value.
- 00000101 = 4 + 1 = 5
- 00000000 = 0
- 01111111 = 127
- 11111011 = -128 + 64 + 32 + 16 + 8 + 2 + 1 = -5
- 10000000 = -128
Positive values have an MSB of 0, while negative values have an MSB of 1. The two’s-complement representation of -5 is therefore 11111011. There is only one zero pattern: 00000000; the system does not need a separate negative zero.
How does two’s-complement representation support negation and addition?
To negate a value, invert every bit and add 1, keeping the declared width. This is called invert-and-add-one.
For example, begin with positive 5:
00000101 → invert: 11111010 → add 1: 11111011
Thus, 11111011 represents -5. The process works in reverse as well: inverting 11111011 and adding 1 produces 00000101.
Once negative values use this encoding, addition remains ordinary binary addition. For example, 5 + (-3) uses:
00000101 + 11111101 = 1 00000010
The eight-bit result is 00000010, or 2. The carry beyond the eighth bit is discarded because the word is fixed at eight bits. Subtraction can use the same rule by negating the subtracted value and adding it.
What range and overflow rules apply to two’s complement in binary?
An n-bit two’s-complement word represents values from:
-2n-1 through 2n-1 – 1
For eight bits, that range is -128 through 127. The range is asymmetric because one bit position has the negative weight -128, while the positive weights add up only to 127.
Overflow occurs when the exact mathematical result falls outside this fixed-width range. Conceptually, when adding two positive values, a negative-looking result indicates overflow. When adding two negative values, a nonnegative result indicates overflow. Adding operands with different signs cannot overflow.
For example, 01111111 (127) plus 00000001 (1) produces 10000000, which reads as -128 in eight-bit two’s complement rather than 128. The bit pattern is valid, but the signed result has overflowed. Similarly, -128 plus -1 wraps to the bit pattern for 127, signaling negative overflow.
