Math Fundamentals18 sections · 814 units
Open in Course

Two's Complement

Standard for negatives

Two's complement represents negative numbers so that addition works without special cases. To negate a number, flip all bits and add 1.

Example: Negate 0000010100000101 (+5+5 in 8-bit). Flip bits: 1111101011111010. Add 1: 1111101111111011. This is 5-5 in two's complement. To verify: 00000101+11111011=10000000000000101 + 11111011 = 100000000. The overflow bit is discarded, leaving 0000000000000000 (zero), confirming they are opposites.

In nn-bit two's complement, the range is 2n1-2^{n-1} to 2n112^{n-1} - 1. For 8 bits: 128-128 to 127127. The leftmost bit still indicates sign (1 for negative), but the encoding makes arithmetic automatic.