Monkey Raptor

Monday, November 25, 2013

How to Convert Binary to Decimal?

The numeral system we always use is the Decimal System, which consists of ten different numbers:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9

The Binary System is very much used in computational world, the computor, to represent the bit encoded data. This numeral system only consists of 2 numbers :
0 and 1

Converting the binary to decimal

It's easier if I just put an example of this.
But before we start, to indicate the different system, usually the number has a subscript thingy so we won't be confused between those two.
Like so: 10012 or 110012 for binary numbers, and 102410 or 235710 for decimal.

Example converting binary to decimal
  • 1012 = (1 x 22) + (0 x 21) + (1 x 20)
    1012 = (4 + 0 + 1)10
    1012 = 510

  • So the binary number of 101 is equal to 5 in decimal numeral system.
  • 111012 = (1 x 24) + (1 x 23) + (1 x 22) + (0 x 21) + (1 x 20)
    111012 = (16 + 8 +4 + 0 + 1)10
    111012 = 2910
    So the binary number of 11101 is equal to 29 in decimal numeral system.
  • 10002 = (1 x 23) + (0 x 22) + (0 x 21) + (0 x 20)
    10002 = (8 +0 + 0 + 0)10
    10002 = 810
    So the binary number of 1000 is equal to 8 in decimal numeral system.

Have you noticed the pattern? Each digit of the binary number is an increasing power of 2, starts from the rightmost to the leftmost. So, the last (rightmost) binary digit is multiplied by 20, then move to the left binary number, and the exponent is increased by one.


Converting decimal to binary

This is the reversed method of the example above.

For instance:
We want to convert the decimal number 7 (710) to binary.
To do that, we iteratively divide that number with 2 and use the remainder as the binary digit.
I put a picture of the solution for that:
converting decimal to binary

The first remainder is as the ending digit, and the last will be placed at the starting of the binary digit. So, 710 = 1112.

Another example:
1810 = (..?..)2
converting decimal to binary
The solution of that will be 10010. So 1810 = 100102
That's about it.
  • The image of Leibniz is under Wikimedia Commons.
  • I made a simple converter of Hexadecimal, Binary, and Decimal on Port Raptor using parseInt(), and toString().
How to Convert Binary to Decimal?
http://monkeyraptor.johanpaul.net/2013/11/how-to-convert-binary-to-decimal.html

No comments

Post a Comment

Tell me what you think...