Sign-magnitude is the most human-intuitive way to store a signed integer: dedicate one bit to the sign and use the rest for the plain magnitude, exactly like writing a minus sign in front of a number. This converter shows the precise bit layout for any signed integer at common widths.
How it works
For a width of W bits:
- The most significant bit is the sign —
0means positive,1means negative. - The remaining
W - 1bits hold the magnitude (absolute value) in ordinary unsigned binary.
Because the sign and magnitude are independent, the representable range is symmetric: -(2^(W-1) - 1) to 2^(W-1) - 1. Like one’s complement, zero can be written two ways — positive zero (0 000…0) and negative zero (1 000…0).
Worked examples
Encoding −42 in 8 bits:
- Take the magnitude: 42 in unsigned 7-bit binary =
010 1010 - Prepend the sign bit
1for negative - Result:
1010 1010=0xAA
Positive 42 is 0010 1010 = 0x2A — the only difference is that leading sign bit.
Encoding −1 in 4 bits:
- Magnitude: 1 =
001 - With sign bit:
1001 - Negative zero in 4 bits would be
1000(sign=1, magnitude=0)
Ranges by bit width
| Bit width | Positive range | Negative range | Both zeros |
|---|---|---|---|
| 4 bits | 0 to +7 | −1 to −7 | +0 (0000), −0 (1000) |
| 8 bits | 0 to +127 | −1 to −127 | +0 (00000000), −0 (10000000) |
| 16 bits | 0 to +32,767 | −1 to −32,767 | +0 and −0 |
| 32 bits | 0 to +2,147,483,647 | −1 to −2,147,483,647 | +0 and −0 |
Notice that 8-bit sign-magnitude holds 255 distinct values (−127 to +127 plus two representations of zero), compared with 256 distinct values for 8-bit two’s complement (−128 to +127).
Why sign-magnitude lost to two’s complement
Sign-magnitude makes negation trivial — just flip the sign bit — but it creates serious problems for arithmetic:
- Addition requires sign checking. To add two sign-magnitude numbers the hardware must compare their signs and either add or subtract the magnitudes, then determine the result’s sign. This takes extra logic compared with two’s complement where addition is always the same operation.
- Dual zero causes comparison trouble. Positive zero and negative zero are bit-for-bit different patterns but must compare as equal. Every comparison circuit needs extra handling.
- Subtraction is awkward. There is no simple “negate and add” shortcut.
Two’s complement solves all three problems at the cost of an asymmetric range (one extra negative value). Every modern integer ALU uses two’s complement for exactly this reason.
Where sign-magnitude still lives
Despite its arithmetic awkwardness, sign-magnitude survives in one critical standard: IEEE 754
floating-point numbers. A float or double has a dedicated sign bit separate from the exponent
and significand, exactly the sign-magnitude idea. The sign bit can be flipped independently to
negate a float, which is why std::abs(float) in C++ is a single bitwise AND on most architectures.
The dual-zero issue also reappears in floating-point: +0.0 and −0.0 compare as equal but behave
differently in some edge cases (e.g., division).