Sign-Magnitude Converter

Encode signed integers as a sign bit plus a plain magnitude in binary.

Free sign-magnitude converter. Enter a signed integer and bit width to see its sign-magnitude binary, where the top bit is the sign and the rest is the magnitude, plus hex and the dual-zero note. Runs in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How does sign-magnitude work?

The most significant bit is the sign: 0 for positive, 1 for negative. The remaining bits hold the absolute value (magnitude) in plain binary. So -5 in 8 bits is 10000101.

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:

  1. The most significant bit is the sign — 0 means positive, 1 means negative.
  2. The remaining W - 1 bits 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:

  1. Take the magnitude: 42 in unsigned 7-bit binary = 010 1010
  2. Prepend the sign bit 1 for negative
  3. 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 widthPositive rangeNegative rangeBoth zeros
4 bits0 to +7−1 to −7+0 (0000), −0 (1000)
8 bits0 to +127−1 to −127+0 (00000000), −0 (10000000)
16 bits0 to +32,767−1 to −32,767+0 and −0
32 bits0 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).