Two's Complement Calculator for Binary – Free

This two's complement calculator negates a binary word: it returns the pattern you get by inverting every bit and adding one, at exactly the width of the input.

How to use the Binary Two's complement Converter tool

  1. Enter the pattern in the Binary word box, padded with leading zeros to the word size you want.
  2. Select Convert to negate the word.
  3. Read the two's complement in the Result box. It has the same number of bits as your input.
  4. Select Copy to take the result, or Example to negate the 8-bit sample 00101101.

How two's complement works

Two's complement is how nearly every processor stores signed integers. In an n-bit word, the negative of x is the pattern for 2^n - x. The top bit ends up as 1 for negative values, and addition works with the same circuit for signed and unsigned numbers. An n-bit word covers -2^(n-1) to 2^(n-1) - 1 with a single zero.

The textbook recipe is to invert the bits and add one. A faster route by hand: copy the bits from the right up to and including the first 1, then invert everything to the left of it.

Worked example: negating 00101101

The sample word is 45. Inverting gives 11010010, and adding one gives 11010011. As an unsigned number that pattern is 211, which is 256 - 45. Read as a signed 8-bit integer it is -45.

With the shortcut, the rightmost 1 of 00101101 is the last bit, so only that bit is copied and the seven bits to its left are inverted. The result is the same 11010011. Feeding it back into the tool returns 00101101, because negating twice restores the original.

00101101  ->  11010011
11010011  ->  00101101
0000000000101101  ->  1111111111010011
00000000  ->  00000000
10000000  ->  10000000

Word size comes from your input

There is no width selector. The number of digits you type is the word size, so leading zeros are significant. Five entered as 0101 returns 1011, the 4-bit form of -5. Entered as 00000101 it returns 11111011, the 8-bit form. Without the leading zero, 101 returns 011, which is rarely what you want.

Spaces between groups are ignored and one 0b prefix is removed, so 0b0000 0101 counts as eight bits. Words can be up to 65,536 bits long. The tool takes a bit pattern, not a decimal number or a minus sign.

Two special patterns

Zero is its own negative. Inverting all zeros gives all ones, and adding one overflows back to all zeros. The carry out of the top bit is discarded.

The other fixed point is the most negative value, a 1 followed by zeros. In 8 bits that is -128, and +128 does not fit, so 10000000 returns 10000000. This is the overflow case behind bugs such as the absolute value of INT_MIN staying negative.

Frequently asked questions

How do I find the two's complement of a binary number?

Flip every bit, then add one to the result, keeping the same number of bits and discarding any carry out of the top. For 00101101 the flip gives 11010010 and adding one gives 11010011.

How do I write -5 in 8-bit two's complement?

Enter positive five as an 8-bit word, 00000101, and select Convert. The result 11111011 is the 8-bit two's complement encoding of -5.

Why did 10000000 come back unchanged?

That pattern is the most negative number of its width. Its positive counterpart is one past the largest value the word can hold, so negation wraps around to the same bits.

Does the calculator show the decimal value?

No. It outputs only the negated bit pattern. To see what a pattern means as a signed and an unsigned decimal number, paste it into the Binary Signed unsigned Converter.

Is two's complement the same as bitwise NOT?

No. Bitwise NOT only flips the bits, which is the one's complement. Two's complement adds one after the flip. The two results are always one apart, with all ones wrapping around to all zeros.

Related tools