Two's Complement Calculator

Find the two's complmenet of a binary number with the below calculator.

OR
Result
-

What is two’s complement in binary?

In the binary number system, twos complement is a method for representing “signed integers”. You might ask what a signed integer is? Well, a signed integer is a positive or negative number. In “twos complement we use the digit with the greatest value (the leftmost digit) to determine the sign of a number. A number with a leftmost digit (often called the most significant bit) of 1 is negative. Meanwhile a number with a 0 as the most significant bit is a positive number. You can look at some examples below to learn how this works.

How does two’s complement work?

Two’s complement works as a system that can be used to represent both positive and negative integers when working with binary numbers. To find the two’s complement of any binary number you always follow the same process. First, you invert all the bits. This requires simply flipping all the os to 1s and then all the 1s to 0s. Then importantly you need to add 1 to the number to get the two’s complement.

In a binary system two’s complement only works with a representable range. For example, in a 4-bit system, the representable range is -8 to 7, while in an 8-bit system, the range is -128 to 127. If you go outside the range then you risk integer overflow or underflow. Integer overflow means that when you add to positive numbers the result “wraps around” and you end up getting a negative number as a result. Integer underflow implies the opposite, when you add two negative numbers or subtract a large positive binary number and the result is less than the minimum end of the range you get a positive number. This is a limitation of the two’s complement system you should be aware of when working with it.

How to find two’s complement?

To find the two’s complement of a number let’s follow some really simple steps:

  1. Take your binary number and invert all the bits (i.e 0101 for the number 5 becomes 1010)
  2. Add 1 to the least significant bit (the rightmost bit e.ge 1010 + 1 = 1011)

The results then represent the negative version of that number i.e (1011 = -5)

Two’s complement examples

Let’s look at some examples of how to perform two’s complement. Remember you can always check these results with the above two’s complement calculator.

Binary Two's Complment Example Rules.  

4-bit two’s complement table

BinaryDecimalBinaryDecimal
011171001-7
011061010-6
010151011-5
010041100-4
001131101-3
001021110-2
000111111-1
000001000-8

How to convert two’s complement to decimal?

You can convert a two’s complement number to decimal by following these simple steps:

  1. Check the left most digit (most significant bit). If it is 0 the number is positive, If it is 1 the number is negative.
  2. If the number is negative numbers (right most digit is 1), then we need to invert the bits.
  3. If we need to invert the bits then flip all the 1s to 0s and 0s to 1 (including the right most digit!)
  4. Convert the number to decimal (you can always you our binary to decimal converter)
  5. If we had a negative number put the negative sign first!

What is zero in two’s complement?

Zero in two’s is always 0. In a four-bit system that is commonly represented as 0000 while in an 8-bit system that is commonly represented as 00000000.

What is two’s complement addition?

An addition with two’s complement works exactly the same as a normal binary addition. To add binary numbers add right to left bit by bit. Remeber the binary addition rules that 1 + 1 = 10, 1 + 0 = 1 and 0 + 0 = 0. Make sure that you carry values between places (bits) as required. The most important difference to look out for here is the overflow. To check this you can determine if the carry into the most significant bit (right-most digit) is different from the carry out of the most significant bit (right-most digit). If so you know that an overflow has occurred.

What is two’s complement subtraction?

Subtraction with two’s complement can work just like addition! For example, say you want to subtract 5 from 7 (7 - 5) in binary (so 00000111 - 00000101). The first thing to do is find the two’s complement of 5 (Follow the steps above the answer should be 11111010). Now we add 7 and -5 (or 00000111 + 11111011). You can always use our binary addition calculator for this! The result you should get for this example is 00000010 which is 2 (and we know 7 -5 = 2). How neat is that!

Related Tools

More Related Resources