| Integers: 1's complement | |||||||||||||
| Another way to represent negative values: | |||||||||||||
| Negate (flip) each bit. | |||||||||||||
| Use the operator ~ to represent flipping each bit. | |||||||||||||
| ~B is B with all of its bits flipped. | |||||||||||||
| This is called 1's complement (1C). | |||||||||||||
| Example: 11ten is 01011 in 5-bit unsigned binary. Call this number B. | |||||||||||||
| B = 01011 | |||||||||||||
| -B = 10100 | |||||||||||||
| Converting from base 10 to N-bit 1C | |||||||||||||
| 1. Ignoring sign, convert value to unsigned N-bit value. | |||||||||||||
| 2. If sign is negative, negate (flip) all bits. | |||||||||||||
| 1C to base 10 | |||||||||||||
| 1. If sign bit (msb) is 1, flip all bits. | |||||||||||||
| 2. Convert N-bit unsigned value to base 10, using negative value if sign bit was 1. | |||||||||||||
| Range of values | |||||||||||||
| Number of positive values (including +0): 2N-1 | |||||||||||||
| Number of negative values (including -0): 2N-1 | |||||||||||||
| Total number of different values: 2N - 1 | |||||||||||||
| Negation | |||||||||||||
| To negate a number, flip all bits. | |||||||||||||
| Problems | |||||||||||||
| 2 zeroes, as in signed magnitude | |||||||||||||
| addition is complicated, but easier than in signed magnitude | |||||||||||||
| Since it has the same problems as SM, why look at 1C? | |||||||||||||
| Because it leads to a better representation. | |||||||||||||