Maths & Computing

Sign-Magnitude Calculator

Convert any signed decimal integer to its sign-magnitude binary representation — or decode a sign-magnitude binary string back to decimal. Choose your word size, see every bit labelled, and compare directly with one's complement and two's complement.

sign-magnitude-calculator
Sign-magnitude result
Sign bit Magnitude bits
Sign bit
Magnitude (binary)
Magnitude (decimal)
Signed representations comparison
Encoding Binary Hex
Sign-magnitude
One's complement
Two's complement
Unsigned binary
Representable range for selected word size
Sign-mag: — Two's comp: —

How sign-magnitude binary works

Sign-magnitude is the most human-intuitive way to represent a signed binary integer: the leading bit carries the sign (0 = positive, 1 = negative) and the remaining bits carry the magnitude in standard unsigned binary. A 4-bit word therefore contains 1 sign bit and 3 magnitude bits.

Decimal → Sign-Magnitude ───────────────────────────────────────────── 1. If the number ≥ 0 : sign bit = 0 If the number < 0 : sign bit = 1 2. Convert |value| to binary 3. Left-pad with zeros to fill (n − 1) magnitude bits 4. Prepend the sign bit Example −19 in 8-bit sign-magnitude Sign bit : 1 (negative) |−19| : 19 = 0001 0011 Result : 1 001 0011 → 0x93 Sign-Magnitude → Decimal ───────────────────────────────────────────── 1. Read MSB → sign (0 = +, 1 = −) 2. Read bits [n−2 … 0] → unsigned magnitude 3. Apply sign to magnitude

Sign-magnitude vs one's complement vs two's complement

All three schemes encode signed integers in fixed-width binary, but they differ in how negative values are stored, and those differences matter for hardware design.

Sign-magnitude stores the absolute value and a separate sign bit. The approach is easy to understand and inspect visually, but it has two representations of zero (positive zero 0000 0000 and negative zero 1000 0000), and addition requires a comparator to handle mixed signs — making adder circuits more complex.

One's complement negates a number by flipping every bit. It also has two zeros and the same adder complication (end-around carry), but it is symmetric and slightly simpler than sign-magnitude to negate in hardware.

Two's complement negates by flipping every bit and adding one. It has a unique zero, a slightly wider negative range (−128 to +127 in 8 bits vs −127 to +127 for the other two), and lets the same binary adder handle both signed and unsigned arithmetic without modification. This is why every mainstream CPU has used two's complement for signed integers since the 1970s.

Sign-magnitude survives today in the sign bit of IEEE 754 floating-point numbers, where the fraction is an unsigned magnitude and the sign is stored separately — exactly the same idea applied to real-number arithmetic.

Worked examples

The table below shows several values encoded in 8-bit sign-magnitude, one's complement, and two's complement side by side. Notice that positive values are identical across all three schemes, while negative values diverge.

Decimal Sign-mag One's comp Two's comp Hex (SM) ──────────────────────────────────────────────────── +127 0111 1111 0111 1111 0111 1111 0x7F +1 0000 0001 0000 0001 0000 0001 0x01 0 0000 0000 0000 0000 0000 0000 0x00 −0 1000 0000 1111 1111 n/a 0x80 −1 1000 0001 1111 1110 1111 1111 0x81 −19 1001 0011 1110 1100 1110 1101 0x93 −127 1111 1111 1000 0000 1000 0001 0xFF −128 overflow overflow 1000 0000 —

Where sign-magnitude is still relevant

Despite being supplanted by two's complement in general-purpose ALUs, sign-magnitude appears in several modern contexts.

IEEE 754 floating-point — The sign of a float or double is a single sign bit followed by a biased exponent and an unsigned fraction. Negating a float is literally just flipping one bit, which is elegant and fast.

Decimal encodings — Packed BCD and certain financial formats keep a sign nibble separate from the magnitude digits, mirroring the sign-magnitude philosophy at the decimal level.

Analogue-to-digital converters — Offset binary and some ADC output codes are closely related to sign-magnitude and are common in DSP pipelines.

Education — Sign-magnitude is the standard starting point for teaching signed binary because the connection between the written number and its encoding is immediately obvious, before students move on to the more abstract but hardware-efficient two's complement.

Common questions

  • Sign-magnitude (also called sign-and-magnitude or signed magnitude) is one of the earliest methods for representing signed integers in binary. The most significant bit (MSB) is the sign bit: 0 denotes a positive number and 1 denotes a negative number. The remaining bits hold the absolute value (magnitude) of the number in ordinary binary. For example, in 8-bit sign-magnitude, +5 is 00000101 and −5 is 10000101.
  • First, determine the sign: set the sign bit to 0 for positive, 1 for negative. Then convert the absolute value of the number to binary and pad with leading zeros to fill the remaining bits. For a word of width n, the magnitude uses n − 1 bits. Example: −19 in 8-bit sign-magnitude: sign bit = 1, magnitude of 19 = 0010011, result = 10010011.
  • Read the most significant bit. If it is 0 the number is positive; if it is 1, the number is negative. Convert the remaining n − 1 bits from binary to decimal to get the magnitude, then apply the sign. For example, 10010011 → sign = negative, magnitude bits 0010011 = 19, result = −19.
  • For an n-bit sign-magnitude integer the range is −(2^(n−1) − 1) to +(2^(n−1) − 1). An 8-bit word covers −127 to +127. Notice this is one less than two's complement (−128 to +127) because sign-magnitude has two representations of zero (00000000 and 10000000), consuming one code that two's complement uses for an extra negative value.
  • Sign-magnitude has three well-known drawbacks: (1) two representations of zero (+0 and −0) complicate equality checks; (2) addition and subtraction require separate sign logic rather than a single binary adder, making hardware circuits more complex; (3) the representable range is slightly smaller than two's complement for the same bit width. For these reasons, virtually all modern CPUs use two's complement for signed integers.
  • Sign-magnitude is used in IEEE 754 floating-point numbers for the sign bit of the significand and exponent (the fraction is stored as a magnitude, the exponent uses biased notation). It also appears in some BCD encodings, certain legacy communication protocols, and educational contexts where its intuitive structure makes binary arithmetic easier to teach.
  • All three are ways to encode signed integers in binary. Sign-magnitude stores the absolute value with a dedicated sign bit. One's complement flips all bits of the positive representation to get the negative; it also has two zeros. Two's complement flips all bits then adds one to get the negative representation; it has a unique zero and enables simple carry-based arithmetic, which is why it dominates modern hardware.
  • This calculator handles integers only. Fractional sign-magnitude binary exists as a concept (the binary point is placed after the sign bit), but in practice IEEE 754 floating-point — which uses a sign bit alongside a biased exponent and a binary fraction — is the standard. Use a dedicated floating-point converter if you need fractional binary representations.