Here is the two's complement calculator (or 2's complement calculator), a fantastic tool that helps you find the opposite of any binary number, and turn this two's complement to a decimal value. You have an opportunity to learn what the two's complement representation is, and how to work with negative numbers in binary systems. In the text, you can also find how this two's complement converter works, or how to turn any signed binary to decimal by hand.
How to work with negative numbers in binary? - 2's complement representation
In the binary system, all numbers are a combination of two digits, 0
or 1
. Each digit corresponds to a successive power of 2, starting on the right.
For example, 12
in binary is 1100
, as 12 = 8 + 4 = 1*2³ + 1*2² + 0*2¹ + 0*2⁰
(using scientific notation). An extended version of the binary system is the hexadecimal system (which uses base 16 instead of base 2). The latter is frequently used in many computer softwares and systems.
Learning about binary leads to many natural questions arising - what about negative numbers in the binary system? Or how do I subtract binary numbers? As we can only use 1
to show that something is present, or 0
to mean that there is a lack of that thing, there are two main approaches:
-
Two's complement representation, or, in other words, signed notation - the first bit tells about the sign. The convention is that a number with a leading
1
is negative, while a leading0
denotes a positive value. In an 8-bit representation, we can write any number from -128 to 127. The name comes from the fact that a negative number is a two's complement of a positive one. -
Unsigned notation - a representation that supports only positive values. Its advantage over the signed one is that, within the same 8-bit system, we can get any number from 0 up to 255.
As long as we need to add or multiply positive numbers, the unsigned notation is good enough. But, usually, the more practical solution is to work with negative numbers as well. A useful thing about the 2's complement representation is that subtraction is equivalent to an addition of a negative number, which we can handle.
How to use two's complement calculator? Two's complement converter in practice
Whenever you want to convert a decimal number into a binary value in two's complement representation, follow these steps:
-
Choose the number of bits in your notation. The higher value, the broader range of numbers you can input.
-
Write any whole decimal within the range that appears under the
Decimal to binary
section. -
... and that's it - the 2's complement calculator will do the rest of the work! It shows the equivalent binary number, as well as its two's complement.
Do you want to estimate the outcome by hand? This is how two's complement calculator does it:
-
Choose the number of bits in the binaries representation. Let's assume we want values in the 8-bit system.
-
Write down your number, let's say 16. 16 in binary is
1 0000
. -
Add some leading
0
's, so that the number has eight digits,0001 0000
. -
Switch all the digits to their opposite (
0→1
and1→0
). In our case0001 0000 → 1110 1111
. -
Add 1 to this value,
1101 1111 + 1 = 1111 0000
. -
1110 0000
in the two's complement representation is-16
in decimal notation, and is the 2's complement of0010 0000
.
Look, as long as you are proficient in switching digits and adding unity to a binary value, evaluating negative numbers in binary is not a big deal!
Turning two's complement to decimal
Our 2's complement calculator can also work the other way around - converting any two's complement to its decimal value. Let's try to convert 1011 1011
, a signed binary, to decimal. There are two useful methods that help you find the outcome:
-
Convert this signed binary into a decimal, like normal, but multiply the leading digit by
-1
instead of1
. Starting from the right:decimal = 1*2⁰ + 1*2¹ + 0*2² + 1*2³ + 1*2⁴ + 1*2⁵ + 0*2⁶ - 1*2⁷
decimal = 1 + 2 + 8 + 16 + 32 - 128 = -69
-
We can see that the first digit is
1
, so our number is negative. First, find its two's complement, then convert the value to a decimal, and come back to the original value:- Reverse digits,
1011 1011 → 0100 0100
. - Add a unity,
0100 0100 + 1 = 0100 0101
. - Convert to a decimal (starting from the right),
decimal = 1*2⁰ + 0*2¹ + 1*2² + 0*2³ + 0*2⁴ + 0*2⁵ + 1*2⁶ + 0*2⁷
. decimal = 1 + 4 + 64 = 69
.- As
69
is the absolute value of our initial (negative) binary, add a minus sign in front of it. 1011 1011
is-69
in two's complement binary notation.
- Reverse digits,
Signed binary to decimal table
If you want to find any whole number in the two's complement eight-bit representation, you may find this table handy. You can see both the value and its two's complement in the same row.
If you are interested in working with the values of a different number of bits, just use our two's complement calculator to save yourself time and effort!