Convert binary to decimal

Author: Frank Hunt
Date Of Creation: 11 March 2021
Update Date: 1 July 2024
Anonim
How To Convert Binary To Decimal
Video: How To Convert Binary To Decimal

Content

The decimal numeric system has ten possible values ​​(0,1,2,3,4,5,6,7,8, or 9) for each place value. This is in contrast to the binary numerical system that has only two possible values, often represented by a 0 or a 1, for each place value. To avoid confusion when using these different numerical systems, the base of each individual number is often indicated by writing it in subscript. For example, the decimal number 156 can be referred to as 15610 and is read as "one hundred and fifty-six, base ten." The binary number 10011100 can be referred to as "base two" by writing it as 100111002. Since the binary system is the internal language of electronic computers, serious programmers should know how to convert decimals to binary and vice versa. Here's how to do this.

To step

Method 1 of 3: Choosing a conversion method

  • Short division by two with remainder (easy for beginners).
  • Comparison with diminishing powers of two and subtraction.

Method 2 of 3: Method One: Divide shortly by two with remainder

This method is much easier to understand when visualized on paper. It only assumes division by two.


  1. Set up the problem. In this example, let's take the decimal number 15610 convert to binary.
    • Write the decimal number as the dividend in an upside-down "long division" symbol.
    • Write the base of the given system (in our case "2" for binary) as the divisor outside the curve of the division symbol.
  2. Write the integer answer (quotient) below the long division symbol and write the remainder (0 or 1) to the right of the dividend.
    • Basically, if the dividend is an even number, the binary remainder will be 0; if the dividend is odd, the binary remainder will be 1.
  3. Going down, divide each new quotient by two and write the remainder to the right of each dividend. Stop when the quotient is 0.
  4. Starting with the bottom remainder, read the series of remains upwards. For this example you should now have 10011100. This is the binary equivalent of the decimal number 156. Or, written with subscript: 15610 = 100111002
    • This method can be modified from decimal places up to each format. The divisor is 2 because it is the format you want. If the desired result is a different format, replace the 2 in the method with the desired format. For example, if the desired result is the format 9, replace 2 with 9. The desired result will then be in the correct format.

Method 3 of 3: Method Two: Comparison with diminishing powers of two and subtraction.

  1. Write the powers of two in a "binary number system" from right to left. Start at 2, evaluating it as "1". Increase the exponent by 1 for every power. The list, up to ten elements, should look like this. 512, 256, 128, 64, 32, 16, 8, 4, 2, 1
  2. Figure out the greatest power that fits the number you want to convert to binary. In this example, we'll convert the decimal number 15610 to binary. What is the greatest power that fits into 156? Because 128 fits, we write a 1 as the leftmost binary digit and subtract 128 from the decimal number, 156. You now have 128.
  3. Continue to the next lower power of two. Fits 64 in 28? No, so write a 0 for the next binary digit on the right.
  4. Fits 32 into 28? No, so write a 0.
  5. Fits 16 in 28? Yes, so write a 1 and subtract 16 from 28. There are now 12 left.
  6. Fits 8 in 12? Yes, so write a 1 and subtract 8 from 12. You now have 4 left.
  7. Does 4 (power of two) fit in 4 (decimal)? Yes, so write a 1 and subtract 4 from 4. You now have 0 left.
  8. Does 2 in 0 fit? No, so write a 0.
  9. Does 1 fit in 0? No, so write a 0.
  10. Set the binary answer the same. Since there are no more powers of two in the list, you are done. You should now have 10011100. This is the binary equivalent of the decimal number 156. Or, written with subscript: 15610 = 100111002
    • Repeating this method will result in remembering the powers of two, allowing you to skip step 1.

Tips

  • Converting in the other direction, from binary to decimal, is often easier to learn first
  • Practice. Try the decimal number 17810, 6310 and 810 to convert. Its binary equivalents are 101100102, 001111112 and 000010002. Try 20910, 2510 and 24110 convert to, respectively, 110100012, 000110012, 111100012 to get.
  • The calculator that is present within your operating system can make this conversion for you. But as a programmer, you are better off understanding how this conversion works. The calculator's conversion options can be made visible in the "View"> "Programmer" menu.