Integers: 2's complement | |||||||||||
2's complement (2C) may not be intuitively obvious, but it has nice properties | |||||||||||
Negation | |||||||||||
1. flip all bits | |||||||||||
2. add 1 (ignoring any carry out of the msb) | |||||||||||
Example: 11ten is 01011 in 5-bit unsigned binary. Call this number B. | |||||||||||
1. flip bits: | 10100 | ~B | |||||||||
2. add 1: | + 1 | ||||||||||
10101 | -B | ||||||||||