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 are going to do when working with a binary number system.

We have a hard time working 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 stay as we are.

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

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

But even in machines, it is an operation that machines are going to have to do frequently. Although internally they use binary, normally users are going to input the numbers in decimal.

So, at least at some point, almost whenever a program works with numbers (and they are the majority), it will have to convert the user’s inputs from decimal to binary, and the 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’ll tell you how 👇.

Binary to Decimal Conversion

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

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

That is,

To do it easily, we make a table.

  • On the top, we put the digits of the binary number
  • Below, we put the powers of 2
  • Multiply digits by powers. That is, remove the ones that are 0 in binary
  • Sum
Binary10110
Power168421
Multiply1642

Finally, we add the numbers in the last row

Decimal to Binary Conversion

To carry out this conversion, we can use the method of successive division or the method of powers of two.

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

Let’s see it with an example. Suppose we have the same number 22 in decimal, and we want to convert it 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 the form of a table, I’ll show it to you here.

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

The resulting binary number is 11001.

Test the converter

Enter a binary number:

Enter a decimal number: