11111 11 0000 0110 = 610 1111 1010 = -610 0000 0000 010
This representation scheme is called two's complement. It is one of many ways to represent negative integers with bit patterns. But it is now the nearly universal way of doing this. Integers are represented in a fixed number of bits. Both positive and negative integers can be represented. When the pattern that represents a positive integer is added to the pattern that represents the negative of that integer (using the "binary addition algorithm"), the result is zero. The carry out of the left column is discarded.
Here is how to figure out which bit-pattern gives zero when added (using the "binary addition algorithm") to another pattern.
How to Construct the Negative of an Integer in Two's Complement: |
---|
Start with an N-bit representation of an integer. To calculate the N-bit representation of the negative integer:
|
This process is called forming the two's complement of N. An example:
The positive integer: 0000 0001 ( one ) Reflect each bit: 1111 1110 Add one: 1111 1111 ( minus one )