Skip to content
BetterDL

Sign-magnitude

Also called: signed magnitude, sign and magnitude, sign-magnitude representation

A signed number format where the MSB is a sign flag (0 = +, 1 = −) and the other bits hold the size. It has two zeros and needs special adder logic.

Sign-magnitude is the most obvious way to store negative numbers: copy what we do on paper. The MSB is the sign (0 for +, 1 for −), and the remaining bits are the magnitude, read as ordinary unsigned binary.

In 4 bits, 0101 = +5 and 1101 = −5.

It's easy for people to read, but it has two real problems:

  • Two zeros. 0000 is +0 and 1000 is −0. One pattern is wasted, and comparison logic has to treat both as equal.
  • Ordinary adders get it wrong. +1 + (−1) = 0001 + 1001 = 1010, which reads as −2. Hardware would have to compare the signs and subtract magnitudes instead.

With n bits it covers −(2ⁿ⁻¹ − 1) to +(2ⁿ⁻¹ − 1). In 8 bits that's −127 to +127, one value fewer than twos complement because of the second zero.

That's why integers use two's complement. Sign-magnitude still lives on in floating-point numbers, where a separate sign bit sits in front of the exponent and fraction.

Worked examples

Example

Reading 5-bit 10110

Split off the sign, then read the rest.

  1. 1.

    Sign bit 1, so negative.

  2. 2.

    Magnitude 0110 = 4 + 2 = 6.

  3. 3.

    Value: −6.

  4. 4.

    For comparison, the same bits in two's complement are −16 + 4 + 2 = −10.

Example

The range of 5-bit sign-magnitude

The magnitude has 4 bits, so it runs from 0 to 15. With the sign, the values are −15 to +15: 31 different values from 32 patterns, because 0 appears twice (00000 and 10000).

Common mistakes

  • Decoding sign-magnitude with two's complement weights, or the other way round.

  • Saying the most negative value is −2ⁿ⁻¹. That's two's complement. Sign-magnitude stops at −(2ⁿ⁻¹ − 1).

  • Forgetting that −0 exists: 1000 in 4 bits.

Practice Sign-magnitude

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Sign-magnitude is taught in Number Systems.