The binary converter is a handy tool that will enable you to perform a conversion of numbers quickly. You will be able to use it both as a binary to decimal converter and decimal to binary calculator. Read on to learn what is the binary system, how to convert the numbers, and how to use this calculator to obtain correct results.
And don't forget to check out our Mayan numerals converter to understand the Mayan numeral system and learn how to convert any number to Mayan numerals!
What is the binary system?
We usually operate in the decimal system. That means that we use ten different digits, from 0 to 9. If you write down a number, for example, 345, each consecutive digit of this number corresponds to a different power of ten. That means that:
- Digit 5 corresponds to 10⁰ (5 is equal to
5 * 10⁰).
- Digit 4 corresponds to 10¹ (40 is equal to
4 * 10¹).
- Digit 3 corresponds to 10² (300 is equal to
3 * 10²).
In the binary system, there are only two available digits: 0 and 1. That means that the digits of every number correspond to powers of 2 instead of corresponding to powers of 10. For example, we can analyze the number 1111 in the binary system in the following way:
- The last 1 corresponds to 2⁰ (1 is equal to
1 * 2⁰ = 1).
- The second-to-last 1 corresponds to 2¹ (10 is equal to
1 * 2¹ = 2).
- Third-to-last 1 corresponds to 2² (100 is equal to
1 * 2² = 4).
- The first 1 corresponds to 2³ (1000 is equal to
1 * 2³ = 8).
After adding all of these numbers, we get
1 + 2 + 4 + 8 = 15. Number 1111 in the binary system corresponds to 15 in the decimal system.
Converting from decimal to binary
You can use a very simple and efficient algorithm to convert numbers from the decimal to binary system.
- Take your initial number. Divide it by 2.
- Note down the remainder. It is going to be equal to 0 or 1. This will be the last digit of the binary number (the rightmost one).
- Take the quotient. It is your new "initial number".
- Keep repeating the above steps, each time adding the remainder to the left of previously obtained digits.
For example, for number 19, we would have the following steps:
- 19/2 = 9, remainder 1
- 9/2 = 4, remainder 1
- 4/2 = 2, remainder 0
- 2/2 = 1, remainder 0
- 1/2 = 0, remainder 1
Reading from the bottom to the top, 19 corresponds to 10011 in the binary system. Check this result with the binary converter!
Converting from binary to decimal
It is similarly straightforward – all you have to do is reverse the algorithm explained above:
- Take the leftmost digit of your initial number. Multiply it by 2.
- Add the next digit of the binary number. The sum will be your new "initial number".
- Keep repeating these steps, each time first multiplying by 2 and then adding the last digit.
For example, for the binary number 110011, we would have the following steps:
1 * 2 = 2
(2 + 1) * 2 = 6
(6 + 0) * 2 = 12
(12 + 0) * 2 = 24
(24 + 1) * 2 = 50
50 + 1 = 51
110011 corresponds to 51 in the decimal system. Check this result with the binary converter!
Converting negative numbers
We are used to simply adding a minus symbol in front of the number if we want to express a negative number in the decimal system. But the binary system does not allow the minus symbol. So how can we represent negative numbers in binary?
The general concept to express negative numbers in the binary system is the signed notation. That means that the first bit indicates the sign of the number:
0 means positive,
1 is a negative value. The signed notation has two representations:
The one's complement of a negative number in binary is achieved by switching all digits of the opposite positive number to opposite bit values.
The two's complement of a negative number in binary is achieved by switching all digits of the opposite positive number to opposite bit values and adding 1 to the number.
Let's look at an example to better understand the one's and two's complement. We want to convert the number -87 in the decimal system into an 8-bit binary system.
- Find the binary representation of the positive number 87 in the decimal system:
- Switch all digits to the opposite:
1010 1000. That's one's complement.
- Add 1 to the one's complement to get the two's complement:
With these representations, you can make applications like binary subtraction without any problems.
However, to convert fractional numbers, you can't apply the same reasoning: find out how to do that with our binary fraction converter!
How to use the binary converter?
Finally, we can talk about how to use the binary converter. For example, we will transform the number -87 from the decimal to the binary system.
Choose the number of bits. For our example, 8 bits are a good choice since they allow for a range from -128 to 127.
Enter your decimal value in the input field in the decimal to binary section. The calculator displays the result:
- The binary value of the positive opposite of our number, so 87, is:
- The one's complement:
- The two's complement:
The one's and two's complement are calculated as described above, flipping all digits for the opposite number and adding 1 for the two's complement.
The converter also allows the inverse conversion from the binary to the decimal system. Simply type in your binary number in the according field, and see the result in the decimal format displayed below.