In sign and magnitude representation, the most significant bit (MSB) is used as a sign bit:
The remaining 7 bits store the magnitude (absolute value) of the number.
| Denary | Sign and Magnitude | MSB meaning |
|---|---|---|
| +27 | 0 0011011 | 0 = positive |
| -27 | 1 0011011 | 1 = negative |
| +100 | 0 1100100 | 0 = positive |
| -100 | 1 1100100 | 1 = negative |
Range using 8-bit sign and magnitude: −127 to +127. Note: there are two representations of zero (+0 = 00000000 and −0 = 10000000).
Two's complement is the most widely used method for representing negative integers in real computer systems. It has the advantage of having only one representation of zero, and addition works naturally without special rules for negative numbers.
To negate a number in two's complement:
Example: Represent −45 in 8-bit two's complement:
If the MSB is 1 (negative number): invert all bits, add 1, then add a minus sign.
Example: What is 11100110 in denary (two's complement)?
In 8-bit two's complement: range is −128 to +127. The MSB has a weight of −128 (rather than +128).
| Representation | Range (8-bit) | Zeros |
|---|---|---|
| Sign and Magnitude | −127 to +127 | Two: +0 and −0 |
| Two's Complement | −128 to +127 | One: 00000000 only |