Advertisement
Shailrshah

Binary to Decimal Conversion

May 27th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int convert(long int n)
  4. {
  5.     static int decimal;
  6.     static int j;
  7.     if(n==0)
  8.         return decimal;
  9.     if(n%2)
  10.         decimal += pow(2,j++);
  11.     else
  12.         j++;
  13.     convert(n/10);
  14. }
  15. int main()
  16. {
  17.     long int binary;
  18.     printf("Enter the Binary number: ");
  19.     scanf("%ld",&binary);
  20.     printf("The decimal form is %d",convert(binary));
  21.     fflush(stdin);
  22.     getchar();
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement