fork(5) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h> // No GSL...
  4. #include <string.h>
  5.  
  6. int main (int argc, char *argv[]) {
  7.  
  8. // Can't pass args in ideone. Hardcode value
  9. char *wrapper = "110100111001001";
  10.  
  11. int length, llo, i;
  12. long double sum=0;
  13.  
  14. while ( *wrapper && ( *wrapper == '0' ) ) wrapper++;
  15.  
  16. length = strlen(wrapper);
  17. llo = length - 1;
  18.  
  19. for ( i = 0; i < length; i++ ) {
  20. if ( wrapper[llo-i] >= '0' && wrapper[llo-i] <= '1' ) {
  21. int x = wrapper[llo-i] - 48;
  22. sum += x * (int)pow(2,i);
  23. }
  24.  
  25. else printf("Some error.\n");
  26. }
  27.  
  28. printf("%.0Lf\n", sum);
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
27081