Two's Complement Calculator

Two's Complement Visualization
Enter a binary number

Understanding Two's Complement

What is Two's Complement?

Two's complement is a method used in computing to represent signed integers in binary. It's widely used because it allows for simple addition and subtraction operations, regardless of whether the numbers are positive or negative.

Formula for Two's Complement

The two's complement of a binary number is obtained by inverting all bits in the binary number and then adding 1 to the result. Mathematically, for an n-bit number B, its two's complement B' is given by:

\[B' = 2^n - B\]

Where:

  • \(B\) is the original binary number
  • \(n\) is the number of bits
  • \(B'\) is the two's complement of B

Calculation Steps

Let's find the two's complement of 1010:

  1. Start with the binary number: 1010
  2. Invert all bits (one's complement):
    • 1 → 0
    • 0 → 1
    • 1 → 0
    • 0 → 1
    Result: 0101
  3. Add 1 to the result:

    \[0101 + 1 = 0110\]

Therefore, the two's complement of 1010 is 0110.

Example and Visual Representation

1 0 1 0 0 1 0 1 0 1 1 0

This diagram illustrates the two's complement conversion of 1010 to 0110. The top row shows the original number, the middle row shows the one's complement, and the bottom row shows the final two's complement result.