askvity

How do you complement a number?

Published in Binary Numbers 2 mins read

To complement a number, you generally invert its bits (changing 0s to 1s and 1s to 0s). This operation is known as the one's complement.

Understanding One's Complement

The one's complement is achieved by flipping each bit in the binary representation of the number. For example:

  • Original Number (Binary): 01101110
  • One's Complement: 10010001

The key feature of the one's complement is that when you add the original number and its one's complement together, the result is a number consisting entirely of 1s.

Example

Let's take the example from the reference:

  • Original Number (Binary): 0110111
  • One's Complement: 1001000
  • Sum: 0110111 + 1001000 = 1111111

Two's Complement

It's important to distinguish one's complement from two's complement, which is another common way to represent signed numbers. Two's complement is calculated by:

  1. Finding the one's complement.
  2. Adding 1 to the one's complement.

Two's complement is widely used because it simplifies arithmetic operations in computers.

In Summary

Complementing a number typically refers to finding its one's complement, which involves inverting all of its bits. However, it is vital to also be aware of the two's complement representation, which is used in many computer systems.

Related Articles