Language: EN

como-convertir-decimal-binario

How to convert between decimal and binary

The conversion from decimal to binary is one of the most important operations we will perform when working with a binary numbering system.

People find it very difficult to work in binary. It is very uncomfortable, the numbers are very long, and we are not used to it. If someone tells us the number 00110101 in binary, frankly, we are left as we are.

However, if I tell you 53 in decimal… it is a very different thing. We visualize it better, and we could even operate with it (for example, you could multiply it by 5 mentally without too much effort).

So the conversion between binary and decimal is something you will have to do frequently. Simply because people are very accustomed to using the decimal system.

But even in machines, it is an operation that machines will have to perform frequently. Although they use binary internally, users will usually input numbers in decimal.

So, at least at some point, almost every time a program works with numbers (and they are the majority), it will have to convert user inputs from decimal to binary and outputs from binary to decimal.

Don’t “worry”! Fortunately, the conversion of a number to decimal or vice versa is quite simple. Keep reading and I will tell you how 👇.

Conversion from Binary to Decimal

To convert a binary number to decimal, we multiply each binary digit by the power of two corresponding to its position and sum the results.

For example, to convert the binary number 10110 (22) to decimal:

That is,

To do it simply, we make a table.

  1. At the top, we put the digits of the binary number
  2. Below, we put the powers of 2
  3. We multiply digits by powers. That is, we remove those that are 0 in binary
  4. We add them up
Binary10110
Power168421
Multiply1642

Finally, we sum the numbers in the last row

Conversion from Decimal to Binary

To carry out the reverse conversion, from decimal to binary, we can use the method of successive division or the method of powers of two.

  1. We divide the decimal number by 2
  2. We take the remainder of the operation
  3. We repeat the process until the quotient is 0.
  4. The obtained binary bits are the result

Let’s see it with an example. Suppose we have the same number 22 in decimal, which we want to convert to binary.

Using the method of successive division we have,

22 / 2 = 11 remainder 0
11 / 2 = 5 remainder 1
5 / 2 = 2 remainder 1
2 / 2 = 1 remainder 0
1 / 0 = 0 remainder 1

If you find it easier in table form, here it is.

OperationStep 5Step 4Step 3Step 2Step 1Start
Divide / 201251122
Remainder10110

The resulting binary number is 11001.

Try the converter

Enter a binary number:
Enter a decimal number: