Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

two's complement

The way every modern processor stores signed integers - the top bit counts as a large negative amount, and one adder works for both signs.

In n-bit two's complement, bit n-1 has weight -2^(n-1) and the others their usual positive weights, giving the range -2^(n-1) to 2^(n-1)-1; -x is (NOT x) + 1, which equals 2^n - x modulo 2^n.

Examples

  • In 8 bits, −5 is 11111011 (0xFB): invert 00000101 to 11111010, then add 1.

Read the full section →