🔄 Two's Complement Calculator

Calculate two's complement of binary numbers

How to Use This Calculator

1

Enter Binary Number

Input the binary number for which you want to calculate the two's complement. The calculator accepts only 0s and 1s. Examples: 1010, 1100, 1111. Two's complement is the standard method for representing negative numbers in computers.

2

Click Calculate Two's Complement

Press the "Calculate Two's Complement" button to perform the operation. The calculator will: (1) flip all bits (one's complement), (2) add 1 to the result, and display the two's complement.

3

Review Results

The result shows the two's complement in binary format and its decimal equivalent. You'll also see a step-by-step breakdown showing how the two's complement was calculated (one's complement + 1).

Formula

Two's Complement = One's Complement + 1

Step 1: Flip all bits | Step 2: Add 1

How it works:

Two's complement is calculated by first finding the one's complement (flipping all bits), then adding 1 to the result. This is the standard method for representing negative numbers in modern computers because it simplifies arithmetic operations and eliminates the dual zero problem.

Two's Complement Properties:

  • Two's complement of a number x in n bits = 2^n - x
  • For 8-bit numbers: range is -128 to +127
  • Has only one representation for zero: 00000000
  • Most significant bit indicates sign (0 = positive, 1 = negative)
  • Adding a number and its two's complement gives 0 (with overflow)

Example 1: Two's Complement of 1010 (10 in decimal)

Original: 1010

Step 1 (One's complement): Flip all bits → 0101

Step 2 (Add 1): 0101 + 1 = 0110

Result: 0110 (binary) = 6 (decimal)

In 4-bit signed: 1010 = -6, so two's complement of 10 is -6

Note: 10 + (-6) = 4, but 1010 + 0110 = 10000 (overflow, equals 0 mod 16) ✓

Example 2: Two's Complement of 0001 (1 in decimal)

Original: 0001

Step 1 (One's complement): Flip all bits → 1110

Step 2 (Add 1): 1110 + 1 = 1111

Result: 1111 (binary) = -1 in 4-bit signed

Note: 1 + (-1) = 0, and 0001 + 1111 = 10000 (overflow, equals 0) ✓

Example 3: Two's Complement of 0111 (7 in decimal, 8-bit)

Original: 0111

Step 1 (One's complement): Flip all bits → 1000

Step 2 (Add 1): 1000 + 1 = 1001

Result: 1001 (binary) = -7 in 8-bit signed

Note: 7 + (-7) = 0, and 0111 + 1001 = 10000 (overflow) ✓

Frequently Asked Questions

What is two's complement?

Two's complement is a method of representing negative numbers in binary. To get the two's complement: (1) flip all bits (one's complement), (2) add 1. It's the standard method used in modern computers because it simplifies arithmetic and has only one representation for zero.

Why is two's complement preferred over one's complement?

Two's complement is preferred because: (1) it has only one representation for zero (no +0 and -0), (2) arithmetic operations are simpler (no need for end-around carry), (3) subtraction can be done using addition, and (4) it's the standard in all modern computers and programming languages.

How do you read a two's complement number?

In two's complement, the most significant bit (leftmost bit) indicates the sign: 0 means positive, 1 means negative. For positive numbers, read normally. For negative numbers, the value is -(2^n - unsigned_value). For example, in 8-bit: 11111111 = -1, 10000000 = -128.

What is the range of two's complement numbers?

For n-bit two's complement: range is -2^(n-1) to +2^(n-1) - 1. For example, 8-bit: -128 to +127, 16-bit: -32,768 to +32,767, 32-bit: -2,147,483,648 to +2,147,483,647. Note that there's one more negative number than positive numbers.

How does two's complement simplify subtraction?

Two's complement allows subtraction using addition: A - B = A + (-B), where -B is the two's complement of B. This means computers can use the same addition circuit for both addition and subtraction, making hardware design simpler and more efficient.

Can I use two's complement with decimal numbers?

Yes, but the calculator converts the decimal number to binary first. The two's complement is calculated by flipping all bits and adding 1, then converted back to decimal. Enter your decimal number, and the calculator will show both binary and decimal representations.