Science

Sign Magnitude Calculator

Convert between decimal and sign-magnitude binary representation. Compare all four signed number systems (sign-magnitude, two's complement, one's complement, unsigned) side-by-side with step-by-step working. Learn why sign-magnitude is intuitive but inefficient.

sign-magnitude-calc
Sign-magnitude representation
Leftmost bit = sign (0 positive, 1 negative). Remaining bits = magnitude (absolute value).
Sign-magnitude binary
Sign bit
Magnitude bits
Interpretation
Hex

What is sign-magnitude — in plain English

Imagine you're writing numbers on paper. Positive numbers don't need a sign (or you might write "+"), and negative numbers get a minus sign. Sign-magnitude binary does exactly this: one bit stores the sign, the rest store the size (magnitude). It's the most intuitive signed number system because it mirrors how humans write signed numbers.

In 8-bit sign-magnitude, +5 is 0000 0101 — the first 0 means positive, the rest (0000101) means 5. To write -5, just flip the sign bit: 1000 0101. The magnitude (5) stays the same. Simple!

But there's a catch: this simplicity comes at a cost. Sign-magnitude has two major flaws that make it unusable in modern CPUs for integer arithmetic: the dual zero problem and complex addition hardware. It survives today only in IEEE 754 floating-point numbers and as a teaching tool.

How to convert decimal to sign-magnitude binary — step by step

Example: Convert -42 to 8-bit sign-magnitude

Step 1 — Determine the sign The number is negative, so sign bit = 1 Step 2 — Find the magnitude (absolute value) |-42| = 42 Step 3 — Convert magnitude to binary 42 ÷ 2 = 21 remainder 0 21 ÷ 2 = 10 remainder 1 10 ÷ 2 = 5 remainder 0 5 ÷ 2 = 2 remainder 1 2 ÷ 2 = 1 remainder 0 1 ÷ 2 = 0 remainder 1 Reading upwards: 42₁₀ = 101010₂ Step 4 — Pad to fit the bit width 8 bits total, sign bit uses 1, so 7 bits for magnitude 101010 → 0101010 (added one leading 0) Step 5 — Prepend the sign bit Result: 1 0101010 = 10101010

How to convert sign-magnitude binary to decimal — step by step

Example: Convert 10010011 (sign-magnitude) to decimal

Step 1 — Check the sign bit (leftmost) First bit = 1, so the number is negative Step 2 — Extract the magnitude bits Magnitude = 0010011 (everything after sign bit) Step 3 — Convert magnitude to decimal 0010011₂ = 0×64 + 0×32 + 1×16 + 0×8 + 0×4 + 1×2 + 1×1 = 16 + 2 + 1 = 19 Step 4 — Apply the sign Sign bit was 1 (negative), magnitude is 19 Result: -19

Why sign-magnitude is intuitive but inefficient

The dual zero problem: Sign-magnitude represents zero in two ways: 0000 0000 (+0) and 1000 0000 (-0). These are mathematically identical but have different bit patterns, wasting one of the 28 = 256 available patterns. When comparing numbers for equality, hardware must check both zero patterns. In 8-bit sign-magnitude, you get only 255 unique values (-127 to +127) instead of 256.

Addition doesn't work: You can't simply add two sign-magnitude numbers using binary addition. Try 5 + (-2): 0000 0101 + 1000 0010 = 1000 0111 = -7. That's wrong — the answer should be 3! Sign-magnitude addition requires checking eight different cases based on the signs and relative magnitudes. If both numbers are positive, add magnitudes. If both negative, add magnitudes and set sign to negative. If signs differ, compare magnitudes, subtract smaller from larger, give the result the sign of the larger. This complexity requires dedicated hardware that two's complement doesn't need — two's complement addition always works with simple binary addition, no special cases.

Why two's complement won: Modern CPUs use two's complement for integers because: (1) Single zero — no wasted bit pattern. (2) Addition and subtraction use the same hardware as unsigned binary — just add the bit patterns, and overflow detection is straightforward. (3) The range is asymmetric (-128 to +127 in 8-bit) but uses all 256 patterns efficiently. The only downside is that two's complement is less intuitive — negating a number requires inverting all bits and adding 1, not just flipping the sign bit.

Where sign-magnitude is still used today

IEEE 754 floating-point arithmetic: The IEEE 754 standard (used for float and double in nearly every programming language) represents real numbers like 3.14 and -0.005 using three fields: a sign bit (1 bit), an exponent (8 or 11 bits), and a mantissa/significand (23 or 52 bits). The sign bit works exactly like sign-magnitude — 0 for positive, 1 for negative. The mantissa magnitude is always treated as positive; the sign bit alone determines the overall sign. This is why IEEE 754 has +0 and -0 as distinct values (they compare equal but have different bit patterns, which matters for certain edge cases like 1/+0 = +∞ vs 1/-0 = -∞).

Digital signal processing: Some legacy digital-to-analog converters (DACs) and analog-to-digital converters (ADCs) use sign-magnitude internally for specific signal dynamic ranges. Audio processing algorithms occasionally use sign-magnitude when the signal naturally has a sign (e.g., positive vs negative voltage) and a magnitude (amplitude).

Educational contexts: Sign-magnitude remains valuable for teaching binary number systems because it is the most intuitive representation. Students learn unsigned binary, then signed magnitude (just add a sign bit!), then progress to the more complex but efficient two's complement. It's pedagogically useful even though it's not used in production systems.

Sign-magnitude range and bit width

Bit width Sign-magnitude range Two's complement range
4 bits −7 to +7 (15 values) −8 to +7 (16 values)
8 bits −127 to +127 (255 values) −128 to +127 (256 values)
16 bits −32,767 to +32,767 (65,535) −32,768 to +32,767 (65,536)
32 bits −2,147,483,647 to +2,147,483,647 −2,147,483,648 to +2,147,483,647

Notice: Sign-magnitude wastes one bit pattern due to dual zero. Two's complement uses all 2n patterns, giving it one extra negative value. The range formula for sign-magnitude is ±(2n-1 - 1), while two's complement is −2n-1 to +(2n-1 - 1).

Common questions

  • Sign-magnitude is a method of representing signed binary numbers where the leftmost bit (most significant bit) is the sign bit (0 = positive, 1 = negative), and the remaining bits represent the magnitude (absolute value) of the number. For example, in 8-bit sign-magnitude: +5 = 00000101 (sign bit 0, magnitude 5), and -5 = 10000101 (sign bit 1, magnitude 5). It is the most intuitive signed representation because it mirrors how we write signed numbers in decimal (+5 and -5 differ only in the sign).
  • Sign-magnitude has two critical flaws: (1) Dual zero — both 00000000 (+0) and 10000000 (-0) represent zero, wasting one bit pattern. (2) Addition and subtraction require complex hardware with 8 different cases depending on the signs and relative magnitudes. You cannot simply add two sign-magnitude numbers using binary addition: 5 + (-2) = 00000101 + 10000010 = 10000111 = -7, not 3. Two's complement solves both problems: single zero and addition works without special cases.
  • Step 1: Determine the sign. If negative, the sign bit is 1; if positive or zero, the sign bit is 0. Step 2: Find the magnitude (absolute value) of the number and convert it to binary. Step 3: Pad the magnitude with leading zeros to fill the remaining bits (excluding the sign bit). Step 4: Prepend the sign bit. Example: -13 in 8-bit sign-magnitude: Sign = 1 (negative). Magnitude = 13 = 1101 in binary. Pad to 7 bits: 0001101. Result: 10001101.
  • Step 1: Look at the sign bit (leftmost bit). If 0, the number is positive; if 1, the number is negative. Step 2: Take the remaining bits (magnitude) and convert them to decimal using standard binary-to-decimal conversion. Step 3: Apply the sign. Example: 10010011 in 8-bit sign-magnitude: Sign bit = 1 (negative). Magnitude bits = 0010011 = 16 + 2 + 1 = 19 in decimal. Result: -19.
  • For an n-bit sign-magnitude number, the range is -(2^(n-1) - 1) to +(2^(n-1) - 1). Notice this is symmetric around zero but excludes one value because of the dual zero. Examples: 4-bit: -7 to +7 (15 values + two zeros). 8-bit: -127 to +127 (255 values + two zeros). 16-bit: -32,767 to +32,767. 32-bit: -2,147,483,647 to +2,147,483,647. Compare this to two's complement which has an asymmetric range but uses all bit patterns efficiently: 8-bit two's complement is -128 to +127 (256 total values, single zero).
  • Sign-magnitude has two distinct representations for zero: positive zero (00000000 in 8-bit) and negative zero (10000000 in 8-bit). These are mathematically equal but have different bit patterns. This wastes one of the 2^n available bit patterns and complicates comparison operations — you must check both zero patterns when testing for equality to zero. Two's complement and one's complement also have dual zeros, but two's complement is preferred because its addition hardware is simpler.
  • Sign-magnitude is rarely used for integer arithmetic but is essential in IEEE 754 floating-point arithmetic. The IEEE 754 standard (used in virtually all modern computers for decimals like 3.14 and -0.005) represents the sign with a dedicated sign bit, followed by an exponent and mantissa. The sign bit works exactly like sign-magnitude. Some legacy digital-to-analog converters (DACs) and signal processing systems also use sign-magnitude for specific signal dynamic ranges. It remains valuable for teaching binary number systems because it is the most intuitive representation.
  • No, you cannot use simple binary addition for sign-magnitude numbers. Adding 5 + (-2) as 00000101 + 10000010 gives 10000111 = -7, which is incorrect (should be 3). Sign-magnitude addition requires checking 8 different cases: if signs match, add magnitudes and keep the sign; if signs differ, compare magnitudes, subtract the smaller from the larger, and assign the sign of the larger. This complexity is why hardware designers prefer two's complement, where addition always works without special cases.
  • Sign-magnitude is more intuitive (just flip the sign bit to negate) but less efficient. Two's complement is harder to understand initially (negate by inverting all bits and adding 1) but is universally used in CPUs because: (1) Addition/subtraction hardware is simple — just add the bit patterns, no special cases. (2) Single zero — no wasted bit pattern. (3) Overflow detection is straightforward. (4) The range is -2^(n-1) to 2^(n-1)-1, which maximizes the negative range. Sign-magnitude wins only on conceptual simplicity and is used in contexts where arithmetic is not the primary concern (like IEEE 754 sign bits).
  • The number cannot be represented in the given bit width. For example, in 8-bit sign-magnitude the range is -127 to +127. If you try to represent -128 or +128, it overflows — there are not enough bits. The magnitude 128 requires 8 bits (10000000 in binary), but after adding the sign bit, you would need 9 bits total. To represent larger numbers, you must increase the bit width: 16-bit sign-magnitude can represent -32,767 to +32,767. This overflow behaviour is the same across all signed representations.