Advertisement
nontawat1996

base 16 to base 10

Apr 22nd, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. int main()
  6. {
  7.     int i,st=0,j=0,sum=0;
  8.     char code[10000]={'\0'};
  9.     gets(code);
  10.     int n;
  11.     n=strlen(code);
  12.     for(i=0;i<n;i++)
  13.     {
  14.         if(code[i]<48 || i==n-1)
  15.         {
  16.             sum=0;
  17.             int run=0;
  18.             if(i==n-1) j=i;
  19.             else j=i-1;
  20.             for(j;j>=st;j--)
  21.             {
  22.                 if(code[j]>='0' && code[j]<='9')
  23.                 {
  24.                     sum+=(code[j]-'0')*pow(16,run);
  25.                 }
  26.                 else
  27.                 {
  28.                     sum+=((code[j]-'a')+10)*pow(16,run);
  29.                 }
  30.                 run++;
  31.             }
  32.             printf("%d ",sum);
  33.             st=i+1;
  34.         }
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement