Turn a binary number into a decimal number

Author: John Pratt
Date Of Creation: 14 April 2021
Update Date: 26 June 2024
Anonim
How To Convert Binary To Decimal
Video: How To Convert Binary To Decimal

Content

It binary (base 2) number system has two possible values, usually represented as 0 or 1, for each position in a number. The difference with it decimal (base 10) number system is that there are ten possible values ​​(0,1,2,3,4,5,6,7,8, or 9) for each position.

To avoid confusion when using different number systems, the base of a number can be indicated by entering it after the number in subscript. For example, the binary number 10011100 can be written with base 2 by writing it as 100111002. The decimal number 156 can be written as 15610 or in full as "one hundred fifty-six, base 10".

Because the binary system is the machine language of computers, serious programmers must fully understand how to convert binary numbers to decimal numbers. Converting in the opposite direction, from decimal to binary, is often more difficult to learn first.


Note: This is ONLY about calculations and not ASCII translations.

To step

Method 1 of 2: Position system method

  1. In this example, we are going to use the binary number 100110112 convert to decimal. List the powers of two from right to left. Start with 2, this has the value "1". Increase the exponents by 1 for each power. Stop when the number of elements in the list equals the number of digits in the binary number. The number in the example, 10011011, has 8 digits, so the list will look like this: 128, 64, 32, 16, 8, 4, 2, 1
  2. Write the binary number below the list.
  3. Connect the binary numbers with the powers of two with lines. Draw lines connecting each binary digit with the corresponding power of 2 above it. Start at the first binary digit, from the right, and continue until you have connected all the binary digits and powers.
  4. Include all digits of the binary number. If the number is 1, write the corresponding second power below the line, directly below the number. If the number is 0, write 0 below the line.
  5. Add up the numbers below the line. The sum should be 155. This is the decimal equivalent of the binary number 10011011. Or, written with the base in subscript:
  6. If you repeat this method often, you will find that you remember the powers of two better, so you can skip step 1.

Method 2 of 2: Doubling method

  1. This method does not use powers. This makes it more suitable if you want to convert larger numbers by heart, as you only need to remember the subtotal.
  2. Start with the digit to the far left of the given binary number. For each additional digit from left to right, double the previous total and add it to the current digit. For example, to get the number 10110012 to convert to a decimal, we take the following steps:
  3. 1011001 → 0 * 2 + 1 = 1
  4. 1011001 → 1 * 2 + 0 = 2
  5. 1011001 → 2 * 2 + 1 = 5
  6. 1011001 → 5 * 2 + 1 = 11
  7. 1011001 → 11 * 2 + 0 = 22
  8. 1011001 → 22 * 2 + 0 = 44
  9. 1011001 → 44 * 2 + 1 = 8910
  10. Like the position system method, this method can be adapted to convert from any number system to a decimal number. Doubling is used here because the base is two. If the given number has a different base, use that instead of 2. For example, if the number has a base of 37, swap * 2 with * 37. The result will always be a decimal number (base 10). :)

Tips

  • Practice a lot. Try the binary numbers 110100012, 110012, and 111100012. Their decimal equivalents are 20910, 2510, and 24110.
  • The calculator that comes with Microsoft Windows can also do this conversion for you, but if you are a programmer it is better that you have a good understanding of how this conversion works. The options of this calculator can be found via the "View" menu and then "Scientific" (or "Programmer"). With Linux you can use galculator.

Warnings

  • This can be used for unsigned binary (positive numbers only), but not signed, floating point, or fixed point.