A signed binary number is a binary number that can represent negative as well as positive values. Across all common signed encodings the leftmost bit () carries sign information ( for positive, for negative), but how the magnitude is encoded into the remaining bits varies between systems.
There are three standard schemes:
- Sign-and-magnitude representation
- Signed 1’s complement
- Signed 2’s complement
Comparison
For an 8-bit value, each scheme handles a few specific values:
| Decimal | Sign-magnitude | 1’s complement | 2’s complement |
|---|---|---|---|
| 00011001 | 00011001 | 00011001 | |
| 10011001 | 11100110 | 11100111 | |
| 00000000 | 00000000 | 00000000 | |
| 10000000 | 11111111 | (only one zero) | |
| 01111111 | 01111111 | 01111111 | |
| 11111111 | 10000000 | 10000001 | |
| (out of range) | (out of range) | 10000000 |
Sign-and-magnitude
The cleanest mental model: leftmost bit is the sign, remaining bits are the magnitude. Has two zeros and requires sign-aware addition. Details in Sign-and-magnitude representation.
Signed 1’s complement
Negate by inverting every bit, including the sign:
- (every bit flipped)
Range for 8 bits: to . Like sign-and-magnitude, has ( and ). Addition is “almost normal”: add the bits including the sign, then if there’s a carry out of the leftmost position, add it back into the rightmost (the end-around carry).
Signed 2’s complement
Negate by inverting every bit and adding :
Range for 8 bits: to . Asymmetric: the most negative value has no positive counterpart in 8 bits.
This is the preferred representation in almost all modern hardware. Three reasons:
- One zero. is the only zero, no ambiguity between and .
- Same addition for all sign combinations. Add the bits including the sign and discard any carry out of the most significant bit. The result is the correct 2’s complement number.
- Same circuits as unsigned addition. The same physical adder works for both. See 2’s Complement Arithmetic.
Negative 2’s complement to decimal
Two methods for converting a negative 2’s complement number back to decimal:
-
Take the 2’s complement. Invert all bits and add , which gives you the magnitude. Slap a minus sign on it.
-
Subtract the MSB’s place value. Convert as if unsigned, but the MSB contributes instead of .
Example for 8-bit :
- Method 1: invert and add → , so the original is .
- Method 2: .
Both give .
Sign extension
To widen a signed number from bits to bits, replicate the sign bit into the new positions. The value stays the same:
That’s either way (4-bit and 8-bit 2’s complement).
For positive numbers, sign extension is just zero-padding on the left. For negative numbers in 2’s complement, it’s one-padding. The operation is so common in hardware that processor instruction sets include dedicated sign-extend instructions (SEXT, MOVSX, etc.).