Signed number representations facts for kids(Redirected from Two's complement)
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 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)
- 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 is a more difficult way of storing negatives. There are three steps for it:
- Find the positive binary number (e.g. 8base 10 = 0000 1000base 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.
- 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).
Signed number representations Facts for Kids. Kiddle Encyclopedia.