3 ms·
Imagine you're doing your math on a car odometer that only goes up to 4 digits. When you reach 10k it wraps around. For any X it is easy to find the complement
by IIAOPSW 3y ago
Imagine you're doing your math on a car odometer that only goes up to 4 digits. When you reach 10k it wraps around. For any X it is easy to find the complement ~X because you can just map the digits independently (0,1,2,3,4 -> 9,8,7,6,5 and vice versa) then adding 1. By construction each digit in X + (~X-1) will be 9, then adding the 1 back in brings it to 10000, which in odometer math wraps around to 0. So ~X is the additive inverse of X meaning that adding ~X always brings you to the same number as subtracting -X.
Or think of a clock. Subtracting X hours is always the same as adding (12-X) hours. Or any circle, turning counterclockwise X degrees is always the same as turning clockwise (360-X) degrees. The trick is being able to take the compliment digit-wise in order to replace a subtraction with an addition. In binary this is just flipping 0 to 1 and vice versa. In base 10 you just need to remember 5 pairs of digits to switch out with each other.