Thursday, 26 January 2017

Decimal to binary conversion

When I started solving some problems, I realized that I forgot converting decimal number to binary manually because mostly converting using online tools.. :(

Here is simple way to do this.

Suppose you have to convert 35 to binary number then you simple start dividing this with 2.

2/35    -  1(remaining value)

2/17    -  1

2/8      -  0

2/4      -  0

2/2      -  0

2/1      -  1

Now simply collect remaining values in reverse order.
100011 and this is binary number for 35.

to verify you can check like,

(2^5 * 1) + (2^4 *0) + (2^3*0) + (2^2*0)  + (2^1*1) + (2^0*1)
      ↧                ↧                ↧               ↧                ↧               ↧
=   32     +       0      +        0     +        0      +       2     +        1
= 35

And you are done..