Advertisement
AJTAMjid2000

Exercise 2.3

Jun 15th, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. long long htoi(char s[])
  5. {
  6.      int len=strlen(s);
  7.      int i,j=0;
  8.     long long hed,sum=0;
  9.     for(i=len-1;i>=0;i--)
  10.     {
  11.         if(s[i]>='0' && s[i]<='9')
  12.         {
  13.             hed=s[i]-'0';
  14.         }
  15.         else if(s[i]>='A'  &&  s[i]<='F')
  16.         {
  17.             hed=(s[i]-'A')+10;
  18.         }
  19.         else if(s[i]>='a'  && s[i]<='f')
  20.         {
  21.             hed=(s[i]-'a')+10;
  22.         }
  23.         sum+=pow(16,j)*hed;  //otheres ot decimat always power method
  24.         j++;
  25.     }
  26.     return sum;
  27. }
  28. int main()
  29. {
  30.     int i;
  31.      char s[1000];
  32.      scanf("%s",s);
  33.      long long  gross=htoi(s);
  34.      printf("%lld\n",gross);
  35.  
  36.      return 0;
  37.  
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement