Skip to content
digiwleea Tools
Learn Open the lab →

One's complement calculator

One's complement writes a negative number by inverting every bit of its positive value: in 8 bits, 5 is 00000101 and -5 is 11111010. Convert a number either way below, see the steps and the matching two's complement, and add two numbers with the end-around carry.

How to use it

Worked example: -5 + 7 at 8 bits

-5 is the inverse of 00000101, so 11111010, and 7 is 00000111. Adding the patterns gives 1 00000001: the result overflowed into a ninth bit. One's complement does not drop that carry; it adds it back into the lowest bit, giving 00000010, which is 2. In two's complement the same sum just drops the carry, because -5 there is 11111011, already one more.

One's complement and two's complement

Both systems use the top bit as the sign and write positive numbers the same way. One's complement negates by inverting the bits; two's complement inverts and then adds 1. That one step makes the difference: one's complement has two zeros, 00000000 (+0) and 11111111 (-0), and a symmetric range (-127 to 127 at 8 bits), so an adder needs the end-around carry and every comparison has to treat both zeros as equal. Two's complement has a single zero, one more negative value (-128 to 127), and plain binary addition just works, which is why almost every processor today uses it. Some early computers used one's complement arithmetic, and it survives in one well-known place: the Internet checksum in IPv4, TCP and UDP headers is the one's complement of the one's complement sum of the 16-bit words, and RFC 1071 notes that this sum comes out the same whatever the byte order of the machine.

In hardware, the one's complement is the cheapest operation there is: one NOT gate per bit. A subtractor can use it too: A - B = A + NOT B + 1, which is how the adder-subtractor turns an adder into a subtractor with XOR gates and a carry in of 1.

Frequently asked

How do you find the one's complement of a binary number?

Invert every bit: each 0 becomes 1 and each 1 becomes 0. The one's complement of 00000101 is 11111010. As a signed number, that pattern is -5 in one's complement.

What is the difference between one's complement and two's complement?

Two's complement is the one's complement plus 1. One's complement has two zeros and a range of -(2^(n-1) - 1) to 2^(n-1) - 1; two's complement has one zero and reaches one further negative, -2^(n-1). Two's complement addition needs no end-around carry, which is why processors use it.

Why does one's complement have two zeros?

Because inverting 00000000 gives 11111111, and both mean zero: +0 and -0. Hardware and software using one's complement have to treat them as equal.

What is the end-around carry?

When two one's complement numbers are added and the sum carries out of the top bit, that carry is added back into the lowest bit. Without it, sums that cross zero come out one too small.

Where is one's complement used today?

Mainly in checksums: the Internet checksum in IPv4, TCP and UDP is computed with one's complement addition of 16-bit words (RFC 1071). Signed integers in processors use two's complement.

Read how computers store negative numbers in the two's complement lesson, or open the lab and build the adder that does this arithmetic.

Related tools: two's complement calculator, binary calculator and bitwise calculator (NOT is the one's complement).

Open the lab →