Skip to main content

Complement

Mental model for the name

Complement is set theory concept where, when we've a fix set of possible values and complement of A means, all values other than the A in the set is the complement of A.

This word is just borrowed from set theory for a concept which is similar to it.

complement versus negation

In arithmetic,complement and negation aren't the same.

In case of arithmetic negation, we represent 123123 as 123-123 as it's negated value. This then makes 123+123=0123 + {-123} = 0. But in case of fixed width arithmetic, we can't write negative numbers. Instead, we represent negative numbers using complements.

Complement of a number is the rest of the value available to reach the max possible value. Assume, base 10 and N is 3. So 10310^3 is 10001000. For value 123123, the complement is 877877 because 123+877=1000123 + 877 = 1000.

Here if you want to keep the fixed width, so we drop the left most 1, and the value is then 000000.

complement-set

How fixed width produces modulo?

In case of binary number system, for every left bit that's set to 0, the remaining value is actually the modulo value. This is because setting every left most 1 to 0 means we're dividing the number by the value of that position.