Advertisement
10rch

Untitled

Apr 2nd, 2017
63
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.  
  3. long long int conv(int num[11],int max);
  4.  
  5. int main(){
  6.   int num[11],c,i=0,max=0;
  7.     printf("Input numbers 0-9 and letters A-F\n(String length must be less or equal to 10 symbols)\n");
  8.     while((c=getchar())!=EOF){
  9.        if(c>='A' && c<='F'){
  10.         num[i]=c-'A'+10;
  11.         i++;
  12.        }
  13.        if(c>='0' && c<='9') {
  14.             num[i]=c-'0';
  15.             i++;
  16.          }
  17.          max=i;  
  18.    }
  19.    if(max>10) printf("Input is too long\n");
  20.    else printf("%lli\n",conv(num,max));  
  21. }
  22.  
  23.  
  24. long long int conv(int num[11],int max){
  25.   int k,j;
  26.   long long int s=0;
  27.   long long int multi[]={1,16,256,4096,65536,1048576,16777216,268435456,4294967296,68719476736,1099511627776};
  28.     for(j=0;j<max;j++){
  29.          s=s+num[j]*multi[max-j-1];
  30.     }
  31.     return s;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement