Signed number representations

From Wikipedia, the free encyclopedia
(Redirected from Negative binary numbers)
Jump to: navigation, search

Signed Number representations are used to solve the problem of representing negative integers in binary. The problem of trying to store the negative sign (−) of a binary number is that there are no states left to use with which to represent the negative assignment. It is not possible to just use 'off' for minus and 'on' for plus because the computer would have no way of knowing whether it was a digit or a sign.

To overcome this issue computer designers invented two methods for storing negative binary numbers: sign-and-magnitude and 2's complement. These produce alternative representations for signed numbers.

Sign-and-magnitude[change | change source]

Sign and Magnitude works by changing the most significant bit (MSB - the first digit) to a 1 if the number is negative, and reduce the number by one, for example:

0000 0010 (2)

will become...

1000 0010 (-2)

This method of storing negative binary numbers does not work because:

  • Binary arithmetic won't work.
  • We must first know which storage mechanism the compiler of a particular language uses.

1's complement[change | change source]

1's Complement works by swapping 1s for 0s and the 0s for 1s for example:

0000 0010 (2)

will become...

1111 1101 (-2)

Much like the sign-and-magnitude method this is easily defined as a negative number because its most significant bit is 1

2's complement[change | change source]

2's Complement is a more difficult way of storing negatives. There are three steps for it:

  1. Find the positive binary number (e.g. 8base 10 = 0000 1000base 2).
  2. Swap the 1s for 0s and the 0s for 1s (e.g. 0000 1000base 2 becomes 1111 0111base 2).
    This is known as "flipping the bits", or applying logical NOT to the original base 2 representation.
  3. Add 1 (e.g. 1111 0111base 2 + 1base 2 = 1111 1000base 2).

This method is liked because:

  • It's like sign and magnitude; a negative number starts with a 1 and a positive number starts with a 0.
  • The binary arithmetic will work.
  • There is only one value for 0 (0000 0000base 2).