How to Use the Calculator?
To use the calculator, simply enter your number, choose whether it is decimal, hex, or binary, and then select the bit length you want to use. The calculator will automatically display the one’s complement value. The equivalent values in decimal, hex, and octal will also be shown.
What Is One’s Complement?
In ordinary decimal numbers, writing negative values is easy because we simply place a minus sign in front, such as $-5$ or $-12$. But computers store everything using bits, and bits do not naturally contain a separate minus symbol. So computer designers needed a system to represent negative numbers using only $0$s and $1$s. One’s complement was one of the early solutions.
The logic behind it is elegant. Positive numbers are written in normal binary form. Negative numbers are written by taking the positive number and flipping all its bits. In this way, a computer can store both positive and negative numbers using the same fixed number of bits.
For example, with 4 bits, a positive number such as $5$ is written as $0101$. Then $-5$ in one’s complement is simply the flipped version, which is $1010$.
How to Find One’s Complement
Finding one’s complement is a simple and direct process.
- First, write the given number in binary using the required number of bits.
- Then invert every bit, changing each $0$ to $1$ and each $1$ to $0$.
Let us find the one’s complement of decimal $34$ using $8$ bits.
First, write $34$ in binary:
$$34_{10}=00100010_{2}$$
Now invert every bit:
$$\begin{aligned} 34_{10} &= 00100010_2 \\ &\phantom{= \ } \downarrow\downarrow\downarrow\downarrow\downarrow\downarrow\downarrow\downarrow \\ \text{1’s Complement} &= 11011101_2 \end{aligned}$$
So, the one’s complement of $34$ in $8$-bit form is:
$$-34_{10}=11011101$$
Understanding Fixed Number of Bits
While learning about one’s complement, it is extremely important to understand that the number of bits matters. A number written in 4 bits may look different from the same number written in 8 bits.
For example, the decimal number $5$ in 4-bit binary is $0101$. Its one’s complement is $1010$. But in 8-bit binary, $5$ is written as $00000101$. Its one’s complement becomes $11111010$. Both answers represent $-5$ in one’s complement, but one is in 4-bit form and the other is in 8-bit form.
So whenever you solve a one’s complement problem, always pay attention to how many bits are being used. Without that information, the answer is incomplete.
A Table of 4-Bit One’s Complement Numbers
To make the pattern easier to see, let us look at the 4-bit system. In 4 bits, the positive numbers begin with $0$ and the negative numbers begin with $1$. The representations follow a mirror-like pattern because each negative number is the bitwise complement of the corresponding positive number.
$$\begin{aligned} +0_{10} &\rightarrow 0000_2 \\ +1_{10} &\rightarrow 0001_2 \\ +2_{10} &\rightarrow 0010_2 \\ +3_{10} &\rightarrow 0011_2 \\ +4_{10} &\rightarrow 0100_2 \\ +5_{10} &\rightarrow 0101_2 \\ +6_{10} &\rightarrow 0110_2 \\ +7_{10} &\rightarrow 0111_2 \ \end{aligned}$$
Now let us look at the negative side.
$$\begin{aligned} -0_{10} &\rightarrow 1111_2 \\ -1_{10} &\rightarrow 1110_2 \\ -2_{10} &\rightarrow 1101_2 \\ -3_{10} &\rightarrow 1100_2 \\ -4_{10} &\rightarrow 1011_2 \\ -5_{10} &\rightarrow 1010_2 \\ -6_{10} &\rightarrow 1001_2 \\ -7_{10} &\rightarrow 1000_2 \ \end{aligned}$$
Problem with One’s Complement
If you look closely at the previous table, you will notice something surprising: one’s complement has two different representations for zero. Both $0000$ and $1111$ represent zero. This means there is a positive zero and a negative zero.
Mathematically, this is awkward, because in normal arithmetic we expect zero to have only one representation. Having two forms of zero can make calculations and comparisons more confusing than they need to be.
This is one of the main reasons one’s complement is not the most widely used system today. Instead, modern computers use two’s complement, which avoids this problem by giving zero only one representation.
The Formula for Range in One’s Complement
If a system uses $n$ bits, then one bit is used for sign information and the rest help determine the size of the number. In one’s complement, the range is slightly unusual because of the extra zero. The largest positive number is one less than $2^{n-1}$, and the smallest negative number has the same size but negative.
$$\text{Range in } n\text{-bit one’s complement} = -(2^{n-1}-1)\text{ to } +(2^{n-1}-1)$$
For example, if $n=4$, then:
$$2^{4-1}-1 = 2^3-1 = 8-1 = 7$$
So the range is from $-7$ to $+7$. If $n=8$, then:
$$2^{8-1}-1 = 2^7-1 = 128-1 = 127$$
So the range is from $-127$ to $+127$. Notice that there is no $-128$ in 8-bit one’s complement. That missing value is a result of the extra zero representation.
One’s Complement vs Two’s Complement
Although this tutorial focuses on one’s complement, it is also important to understand two’s complement. The difference between the two systems is quite easy to see.
In one’s complement, you form the negative of a binary number by flipping every bit. In two’s complement, you also flip every bit, but then you add $1$ to the result. That small extra step makes a very big difference.
For example, let us take $+5$ in 4-bit binary, which is $0101$. In one’s complement, we flip all the bits to get $1010$, so $1010$ represents $-5$ in one’s complement. In two’s complement, we again start by flipping the bits of $0101$ to get $1010$, but then we add $1$. This gives $1011$, so $1011$ represents $-5$ in two’s complement.
As discussed earlier, one of the biggest disadvantages of one’s complement is that it has two zeros. In a 4-bit system, both $0000$ and $1111$ represent zero. In other words, $0000$ is positive zero, while $1111$ is negative zero. Even though both mean the same value, storing zero in two different ways creates unnecessary confusion and makes the system less efficient.
Two’s complement solves this problem. Because of the extra $1$ added after flipping the bits, the system has only one representation of zero. This makes arithmetic simpler and more practical for computers. That is why modern computers use two’s complement instead of one’s complement.
