# Signed number representations

(Redirected from Negative binary numbers)

Binary is a perfect number system for computers because their memory only has two states: on or off. But there is a problem when trying to store the negative sign (−) of a binary number because there are no states left to use. 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

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.

## 2's complement

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