Why does the eight-bit pattern 11111111 mean −1 rather than 255? It depends on whether the bits are interpreted as unsigned binary or as a signed value. In the signed layout, the most significant bit is the sign bit: 0 indicates a nonnegative value, and 1 indicates a negative value. section 3.1.1
Two’s complement does not encode a negative number by merely switching its sign bit. To obtain −1, start with 00000001, invert every bit, then add 1. The result, 11111111, adds to 00000001 to produce zero when the carry beyond eight bits is discarded. An unsigned byte spans 0–255; an eight-bit two’s-complement value spans −128–127. section 3.1.1
Table 3.2 Binary addition showing why -1 is represented as all 1s
|
Bit position
|
7
|
6
|
5
|
4
|
3
|
2
|
1
|
0
|
|
-1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
|
1
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
1
|
|
Carry
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
|
|
Result
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
The carry column shows why adding the eight-bit encodings of −1 and 1 leaves eight zero bits. section 3.1.1
Rule of thumb: a leading 1 signals a negative value only when the bits are being interpreted using a signed layout. A double-precision floating-point layout also has a sign bit, but divides its other bits into exponent and significand fields. section 3.1.1


