給出一個二進制的非負整數x,x<232,把它轉換成十進制數輸出。
注意數據范圍!!!
1 #include "stdio.h" 2 #include "string.h" 3 const int maxn = 100000; 4 int main(int argc, char const *argv[]) 5 { 6 char indata[maxn]; 7 memset(indata,0,sizeof(indata)); 8 while(scanf("%s",indata)!=EOF) 9 { 10 int n = strlen(indata); 11 unsigned long long sum = 0; 12 for(int i=n-1;i>=0;i--) 13 { 14 unsigned long long k = indata[i]-'0'; 15 sum += (k<<(n-i-1)); 16 } 17 printf("%llu\n",sum ); 18 } 19 return 0; 20 }