Data Representation & Number Systems

sign-magnitude representation

Sign-magnitude is the most obvious way to add negative numbers to binary, and it mirrors how we write them by hand: a leading symbol for the sign, then the size. Here the leftmost bit is reserved as a sign bit (0 means positive, 1 means negative), and the remaining bits hold the plain magnitude. It is exactly like writing +5 or -5: one mark for the sign, the rest for how big the number is.

In 8 bits, +5 is 0 0000101 (sign bit 0, magnitude 5) and -5 is 1 0000101 (sign bit 1, same magnitude 5). The appeal is human readability — you flip just the sign bit to negate a number. But two flaws sink it for general use. First, there are two different patterns for zero: 0 0000000 is positive zero and 1 0000000 is negative zero, which wastes a pattern and forces hardware to treat them as equal even though their bits differ. Second, and worse, ordinary binary addition does not work across the sign: adding the bits of +5 and -5 does not give zero, so the arithmetic unit needs special-case logic to inspect signs and decide whether to add or subtract.

Because of those two problems — a redundant zero and arithmetic that needs awkward special handling — sign-magnitude lost out to two's complement for integers, and almost no modern machine uses it for whole numbers. It is worth knowing anyway for two reasons: it makes clear what problems two's complement was invented to solve, and the idea survives in floating-point numbers, where the sign really is stored as a separate leading bit.

In 8-bit sign-magnitude, +5 is 0 0000101 and -5 is 1 0000101 — same magnitude, flipped sign bit. But 0 0000000 (+0) and 1 0000000 (-0) are two zeros, and adding the bits of +5 and -5 gives 1 0001010 (-10), not zero.

Easy to read, but it has two zeros and ordinary addition fails across the sign bit.

Sign-magnitude is intuitive but loses to two's complement for integers because of its double zero and the special-case logic addition needs. Its leading-sign-bit idea does live on inside floating-point formats.

Also called
signed magnitude符號數值法