Skip to content
Home

Signed number representations in binary: sign-and-magnitude, ones' and two's complement

How negative integers are encoded in fixed-width binary: common schemes (sign-and-magnitude, ones' complement, two's complement, biased), their ranges, arithmetic behavior, examples and practical trade-offs.

Computers must encode both positive and negative integers using a fixed number of binary digits. Signed number representations are conventions that assign one or more bit patterns to negative values and define how arithmetic is performed. The choice of representation affects the numeric range, how zero is represented, how addition and subtraction are implemented in hardware, and how overflow is detected.

Common representations and simple examples

The principal methods used in practice are sign-and-magnitude, ones' complement, two's complement, and biased (offset) representations. Each treats the most significant bit (MSB) as a sign indicator in some way, but the details and arithmetic consequences differ.

  • Sign-and-magnitude: One bit (usually MSB) indicates sign (0 for positive, 1 for negative) and the remaining bits encode the magnitude in ordinary binary. For 4 bits, +3 = 0011 and -3 = 1011. This scheme yields two representations of zero (positive and negative zero) when the magnitude is all zeros.
  • Ones' complement: Negative values are the bitwise inversion of the positive value. For 4 bits, +3 = 0011 and -3 = 1100. Ones' complement also produces two zeros: 0000 and 1111.
  • Two's complement: Negation is formed by inverting all bits and adding one. For 4 bits, +3 = 0011 and -3 = 1101. Two's complement has a single zero (0000) and a convenient arithmetic property that addition and subtraction use the same binary adder as unsigned arithmetic interpreted modulo 2^n.
  • Biased (offset) representation: A fixed bias is added to signed values so that stored patterns are nonnegative; commonly used for floating-point exponents. For example, an 8-bit exponent may store the true exponent plus bias 127 (excess-127).

Numeric ranges and special cases

With n bits, two's complement represents values from -2^(n-1) to 2^(n-1)-1. Sign-and-magnitude and ones' complement both represent roughly -(2^(n-1)-1) to +(2^(n-1)-1) but include two distinct bit patterns for zero. The asymmetry in two's complement gives one extra negative value (e.g., with 4 bits the range is -8..+7), which has implications for absolute-value computations and overflow when negating the most negative number.

Arithmetic behavior and hardware implications

Two's complement is widely used in modern processors because it simplifies integer arithmetic: the same binary adder handles signed addition and subtraction without special sign handling, and there is exactly one representation of zero. Ones' complement requires an "end-around" carry to produce a correct result on addition, and sign-and-magnitude typically requires separate sign logic and conditional magnitude arithmetic. Overflow detection for two's complement is commonly done by checking whether the carry into the sign bit differs from the carry out, or more abstractly by seeing whether adding two numbers of the same sign produces a result with the opposite sign.

Uses, advantages and disadvantages

  • Two's complement: dominant in general-purpose CPUs because of simple hardware, single zero, and natural wraparound consistent with modulo arithmetic. Drawback: the most negative number has no positive counterpart within the same width.
  • Sign-and-magnitude: easier to read and related to human notation (explicit sign plus magnitude). Less convenient for fast arithmetic and also wastes a pattern on negative zero.
  • Ones' complement: historically used in some early machines; simplifies bitwise inversion as negation but shares negative-zero and carry issues.
  • Biased/offset: preferred for storing exponents in floating-point formats because it preserves ordering of exponent fields when compared as unsigned integers.

Practical notes and notable facts

Programmers and compiler writers routinely assume two's complement arithmetic on today's hardware; many language standards either require or expect two's complement behavior for typical integer operations. When working with fixed-width representations, sign extension must be applied when increasing bit width so that the sign bit replicates into the new high-order bits; this preserves numeric value for two's complement and sign-and-magnitude contexts but must be done correctly according to the representation. For further background and implementation details, see additional resources.

Questions and answers

Q: What is the purpose of signed number representations?

A: The purpose of signed number representations is to represent negative integers in binary.

Q: Why is it difficult to store the negative sign of a binary number?

A: It is difficult to store the negative sign of a binary number because there are no states left to use with which to represent the negative assignment.

Q: What would happen if the computer used 'off' for minus and 'on' for plus to represent signed numbers?

A: If the computer used 'off' for minus and 'on' for plus to represent signed numbers, the computer would have no way of knowing whether it was a digit or a sign.

Q: How did computer designers overcome the issue of storing negative binary numbers?

A: Computer designers overcame the issue of storing negative binary numbers by inventing two methods for storing them: sign-and-magnitude and 2's complement.

Q: What do sign-and-magnitude and 2's complement produce?

A: Sign-and-magnitude and 2's complement produce alternative representations for signed numbers.

Q: What is the difference between sign-and-magnitude and 2's complement?

A: The difference between sign-and-magnitude and 2's complement is that sign-and-magnitude represents the sign separately from the magnitude, while the 2's complement represents the sign implicitly by inverting and adding one to the magnitude.

Q: Why do computer designers use sign-and-magnitude and 2's complement to represent negative binary numbers?

A: Computer designers use sign-and-magnitude and 2's complement to represent negative binary numbers because they provide alternative representations that allow for the storage of negative numbers in binary.

Related articles

Author

AlegsaOnline.com Signed number representations in binary: sign-and-magnitude, ones' and two's complement

URL: https://en.alegsaonline.com/art/90333

Share