- Joined
- Jun 30, 2023
The word complement is used a lot in math in the context of something that is opposite to another thing or something that cancels the other thing out (particularly in set theory). It's not a completely illogical choice, but bitwise NOT makes a lot more sense. NOT is sometimes referred to as the logical complement anyway. It fits with similar terminology like converse and contrapositive. You could think of the mappings of booleans/bits as sets with complements if it makes it easier.The name is not particularly helpful in understanding what it actually is... the names "ones' complement" and "two's complement" are kind of terrible, and you'd probably be better off to just learn what they are and try to avoid thinking about whether those names actually mean anything. Particularly, if you know how to do a "ones' complement", you know absolutely nothing by extension about how to do a "two's complement", and vice versa.
Knuth, Donald E. "4.1. Positional Number Systems". The Art of Computer Programming, Volume 2: Seminumerical Algorithms (3rd ed.).
"A two's complement number is complemented with respect to a single power of 2, while a ones' complement number is complemented with respect to a long sequence of 1s."
In other words, they're completely different things, and the fact that their names are similar is more misleading than anything.
Last edited: