Wiktionary
n. 1 (context computing English) The number obtained by complementing every bit of a given number and adding one. A number and its complement add to 2n, where ''n'' is the word size of the machine. 2 (context computing English) The convention by which bit patterns with high bit 0 represent positive numbers from 0 to directly, while bit patterns with high bit 1 represent negative numbers from -1 to , (g: n) being the word size of the machine, and the numeric complement of a number is its two's complement.
Wikipedia
Two's complement is a mathematical operation on binary numbers, as well as a binary signed number representation based on this operation. Its wide use in computing makes it the most important example of a radix complement.
The two's complement of an -bit number is defined as the complement with respect to ; in other words, it is the result of subtracting the number from . This is also equivalent to taking the ones' complement and then adding one, since the sum of a number and its ones' complement is all 1 bits. The two's complement of a number behaves like the negative of the original number in most arithmetic, and positive and negative numbers can coexist in a natural way.
Three-bit two's-complement integersBits
Unsigned
value
Two's
complement
value
011
3
3
010
2
2
001
1
1
000
0
0
111
7
-1
110
6
-2
101
5
-3
100
4
-4
Eight-bit two's-complement integersBits
Unsigned
value
Two's
complement
value
0111 1111
127
127
0111 1110
126
126
0000 0010
2
2
0000 0001
1
1
0000 0000
0
0
1111 1111
255
−1
1111 1110
254
−2
1000 0010
130
−126
1000 0001
129
−127
1000 0000
128
−128
In two's-complement representation, positive numbers are simply represented as themselves, and negative numbers are represented by the two's complement of their absolute value; two tables on the right provide examples for = 3 and = 8. In general, negation (reversing the sign) is performed by taking the two's complement. This system is the most common method of representing signed integers on computers. An -bit two's-complement numeral system can represent every integer in the range to while ones' complement can only represent integers in the range to .
The two's-complement system has the advantage that the fundamental arithmetic operations of addition, subtraction, and multiplication are identical to those for unsigned binary numbers (as long as the inputs are represented in the same number of bits and any overflow beyond those bits is discarded from the result). This property makes the system both simpler to implement and capable of easily handling higher precision arithmetic. Also, zero has only a single representation, obviating the subtleties associated with negative zero, which exists in ones'-complement systems.