# One's Complement

Learn the representation of signed numbers in binary using one's complement.

## We'll cover the following

The sign-magnitude representation has limitations, such as the duplication of zero representations and increased complexity in comparison operations. The inversion-based representation overcomes these limitations and simplifies comparison and arithmetic operations.

## What is one’s complement?

One’s complement representation is another way of representing signed numbers. A number’s representation in one’s complement has the same number of bits as the original number, plus a bit called the sign bit on the extreme left (the MSB). The sign bit denotes that the number is negative if it is set to $1$, and positive if it is set to $0$. To represent a negative number, the other bits hold the complement of the original number in binary. To represent a positive number, the bits hold the number as it is in binary.

Note:Thecomplementof a binary number is the number with all the individual bits inverted. That means that every $1$ turns into a $0$ and vice versa. For example, the complement of the number $1010001$ is $0101110$.

One of the major drawbacks of one’s complement is that it has two representations for $0$, a negative $0$ and a positive $0$. For an $8$-bit representation, these are $00000000$ and $11111111$. This is wasteful, because we lose out on one representation of one number.

### Range

So what is the range of numbers that we can represent with an $n$-bit one’s complement number?

Note:Remember one bit is dedicated to the sign, so that leaves $n-1$ bits for the actual number representation. Following the rule from the previous chapter, the largest number we can represent using $n-1$ bits is $2^{n-1}-1$. So, our range is -$2^{n-1}-1$ to $2^{n-1}-1$.

Get hands-on with 1200+ tech skills courses.