Wednesday, April 29, 2009

Decimal to Binary

Input : any Decimal Number

Output : Binary format 

Logic:

1) Take any natural number say..10.
2)  divide by 2, and find remainder...repeat the same process until u get 0.
divisor number remainder
         2 10 (0)
          ---------------------------------
      2 5 (1)
      ----------------------------------
      2 2 (0)
      ----------------------------------
      2 1 (1)
      ----------------------------------
            0
3) Now look at the remainder pattern from bottom to top, ie. 1010 which is an equivallent for decimal number 10.

No comments:

Post a Comment