Computer Science
Advanced

Two's Complement

Represents negative integers in binary by inverting bits and adding one.

Formula

N=¬N+1-N = \lnot N + 1

Variables

NBinary number

Example

In 8-bit two’s complement, −5 is ~00000101 + 1 = 11111011.

Did You Know?

Two's complement lets computers subtract by adding — which is why almost every CPU uses it for signed integers.