como-convertir-decimal-binario

How to convert between decimal and binary

  • 4 min

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

People find it very difficult to work in binary. It’s very inconvenient, the numbers are very long, and we are not used to it. If anyone tells us the number 00110101 in binary, frankly, we are left clueless.

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

So converting 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 for machines, it’s an operation they will have to perform frequently. Although they use binary internally, users will typically input numbers in decimal.

So, at least at some point, almost any program that works with numbers (and that’s most of them) will have to convert user inputs from decimal to binary, and outputs from binary to decimal.

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

Converting 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 easily, 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. Multiply digits by powers. That is, we remove those that are 0 in binary
  4. Sum them up
Binary10110
Power168421
Multiply1642

Finally, we add the numbers from the last row

Converting Decimal to Binary

To perform the inverse conversion, from decimal to binary, we can use the successive division method or the powers of two method.

  1. Divide the decimal number by 2
  2. Take the remainder of the operation
  3. 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 successive division method 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
Copied!

If you find it easier in table form, I’ll put it here.

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

The resulting binary number is 11001.

Try the Converter

Enter a binary number:
Enter a decimal number: