Sign-Magnitude Converter

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

Ad placeholder (leaderboard)

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).

Example

Encode -42 in 8 bits. The magnitude 42 is 0101010 in 7 bits. Prepend a sign bit of 1 (negative) to get 10101010, which is 0xAA. Positive 42 would be 00101010 — the only difference is that leading sign bit.

Notes

Sign-magnitude makes negation trivial (just flip the top bit) but complicates addition, since the hardware must compare signs and decide whether to add or subtract magnitudes. That overhead is why integer ALUs use two’s complement instead. The format still appears prominently in floating-point: an IEEE-754 number stores its sign as a separate bit, exactly the sign-magnitude idea applied to the significand.

Ad placeholder (rectangle)