Two's complement is a mathematical operation on binary numbers, best known for its role in computing as a method of signed number representation.
The two's complement of an N-bit number is defined as its complement with respect to 2N. For instance, for the three-bit number 010, the two's complement is 110, because 010 + 110 = 1000.
John von Neumann suggested use of two's complement binary representation in his 1945 First Draft of a Report on the EDVAC proposal for an electronic stored-program digital computer.
The two's complement operation is the additive inverse operation, so negative numbers are represented by the two's complement of the absolute value.
Arithmetic operations
Addition
11111 111 (carry) 0000 1111 (15) + 1111 1011 (−5) =========== 0000 1010 (10)
0111 (carry) 0111 (7) + 0011 (3) ====== 1010 (−6) invalid!
Subtraction
11110 000 (borrow) 0000 1111 (15) − 1111 1011 (−5) =========== 0001 0100 (20)