Two's Complement
The standard way to represent signed integers in binary so that addition works uniformly.
Definition
Two's complement represents signed integers so that the same binary addition circuit works for both positive and negative numbers. A negative value is formed by inverting all bits of its magnitude and adding one.
A subtle asymmetry is that the most negative value has no positive counterpart within the same bit width, so negating it overflows. This edge case is a classic source of bugs in code that assumes negation is always safe.
Overflow is the practical hazard: adding two large positive numbers can wrap to a negative result without any error being raised, a silent failure behind many real bugs and security vulnerabilities. Languages and libraries offer checked arithmetic to detect it. Understanding the fixed range of each integer width, and the asymmetry that the most negative value cannot be negated, is essential to writing correct low-level numeric code.
Properties
- A single representation of zero, unlike sign-magnitude.
- The most significant bit indicates sign.
- An n-bit range runs from -2^(n-1) to 2^(n-1)-1.
- Subtraction becomes addition of a negated value.
Why it matters
Two's complement is used by virtually all modern processors because it lets one adder handle signed arithmetic without special cases. It also explains integer overflow: exceeding the range wraps around to the opposite sign.
Fusion connection
Correct signed encoding matters when differencing sensor channels in diagnostics, where an unnoticed overflow could corrupt a computed plasma quantity.