Integer Formats

Sign-Magnitude Representation (Original Binary Data)

To represent a singed decimal number in binary format, it uses the highest bit as sign bit to determine whether the binary number is negative.

00 stands for positive number and 11 means negative number.

One’s Complements (Radix-1 Complements)

  • Positive Number: Same as original.
  • Negative Number: Inverse all bits except the sign bit of a binary number.

Two’s Complements (Radix Complements)

  • Positive Number: Same as original.
  • Negative Number: Plus 11 on one’s complements.

Range of Representation

Suppose the data has nn bits.

Both sign-magnitude representation and one’s complements have +0+0 and 0-0, so the range is [2n11,2n11][-2^{n-1}-1, 2^{n-1}-1]

While two’s complements has only one 00, so the range is [2n1,2n11][-2^{n-1}, 2^{n-1}-1]

In conclusion:

Representation Range
Sign-Magnitude Representation [2n11,2n11][-2^{n-1}-1, 2^{n-1}-1]
One’s Complements [2n11,2n11][-2^{n-1}-1, 2^{n-1}-1]
Two’s Complements [2n1,2n11][-2^{n-1}, 2^{n-1}-1]

Application of Two’s Complements

When doing subtraction, like calculating aba-b, it can be converted to calculating a+(b)a + (-b), where b-b is generated by its two’s complements.

Conversion Between Sign-Magnitude Representation and Two’s Complement

If the number is positive, then the sign-magnitude representation and the two’s complement are the same.

If the number is negative, then the MSB must be 11. The conversion processes are the same:

Reverse all bits except the sign bit, then plus 11.

For example, a sign-magnitude representation is 1101  00011101\;0001. Its two’s complement is:

1101  00011010  1110+11010  1111 1101\;0001 \rightarrow 1010\;1110 + 1 \rightarrow 1010\;1111

Then, the two’s complement can be converted back to sign-magnitude representation with the same process:

1010  11111101  0000+11101  0001 1010\;1111 \rightarrow 1101\;0000 + 1 \rightarrow 1101\;0001

Specially, the two’s complement of 1000  00001000\;0000 can not use this process. Since the range is [128,127][-128, 127], its two’s complement is the same as its sign-magnitude representation, which is 1000  00001000\;0000.

Last updated on