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