One's and Two's Complement Calculator

Original Binary Invert all bits One's Complement Add 1 Two's Complement

Understanding One's and Two's Complement

What are One's and Two's Complement?

One's complement and two's complement are methods used in computing to represent signed integers. They are particularly useful for performing subtraction and representing negative numbers in binary systems.

One's Complement

One's complement of a binary number is obtained by inverting all bits in the binary representation of the number.

Formula: For each bit \(b_i\) in the binary number:

\[b_i' = 1 - b_i\]

Where \(b_i'\) is the complemented bit.

Two's Complement

Two's complement is obtained by adding 1 to the one's complement of a number.

Formula: For a binary number \(B\):

\[Two's Complement(B) = One's Complement(B) + 1\]

Calculation Steps

Let's calculate the one's and two's complement of the binary number 1010:

  1. Original number: 1010
  2. One's Complement:
    1010 → 0101 (invert all bits)
  3. Two's Complement:
      0101 (One's Complement)
    +    1
    -----
      0110 (Two's Complement)

Example and Visual Representation

Binary Number Conversion Process Original Number: 1 0 1 0 (Decimal: 10) One's Complement: 0 1 0 1 (Decimal: 5) Two's Complement: 0 1 1 0 (Decimal: 6) Invert all bits Add 1 Note: Two's complement is used to represent negative numbers in binary. For this 4-bit number, the range is -8 to 7.

This diagram illustrates the original binary number 1010 (top, blue), its one's complement 0101 (middle, green), and its two's complement 0110 (bottom, red).