David W. answered 09/13/20
retired
Just as a review, the reasons for using two-s complement notation are (1) only one representation of 0 [not +0 and -0] and (2) use less hardware [e.g., adders]
Here are the values that may be stored in a 4-bit register::
| Decimal Number | Two-s Complement |
| -8 | 1000 |
| -7 | 1001 |
| -6 | 1010 |
| -5 | 1011 |
| -4 | 1100 |
| -3 | 1101 |
| -2 | 1110 |
| -1 | 1111 |
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
Numbers from -8 to +7 may be represented (note: since there is only one 0, an extra negative number may be stored)..
To convert from binary to two's complement, take the NOT (the 1's complement) of the number and add 1..
To convert from two's complement to binary, take the NOT (the 1's complement) of the number and add 1.
Yes, doing the same operation saves extra circuitry.
The two's complement of 5 (that is, 0101) is 1010 + 1 or 1011.
The binary value of 1011 is 0100 (i.e., the NOT, or one's complement) + 1 or 0101, which is decimal 5.
This problem:
Binary value in computer:
11111111 11111111 11111111 11111111 11111111 11111111 11111111 111110002
NOT (one's complement)
00000000 00000000 00000000 00000000 00000000 00000000 00000000 000001112
Add +1
00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010002
Convert to decimal and append the negative sign :
-8
Note that one's complement values consider the MSB (Most Significant Bit) [the left-most bit] and get a correct result (see the 4-bit table above).