fork(9) download
  1. #include <stdio.h>
  2.  
  3. void outputAsDecimal(char *binary)
  4. {
  5. char digits[200]; // arbitrary size for now
  6.  
  7. for (int i=0; i< 200; ++i)
  8. digits[i] = 0;
  9.  
  10. while (*binary != 0)
  11. {
  12.  
  13. // shift the digits, with carry
  14. int carry = 0;
  15.  
  16. for (int i = 0; i< 200; ++i)
  17. {
  18. int d = digits[i] *2 + carry;
  19. carry = d > 9;
  20. digits[i] = d % 10;
  21. }
  22.  
  23. // or in the new bit
  24. if (*binary++ == '1')
  25. digits[0] |= 1;
  26. }
  27.  
  28. // output with leading zeroes!
  29. for (int i = 199; i >=0; --i)
  30. {
  31. putchar(digits[i] + '0'); // convert to ascii
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. outputAsDecimal("11111111111111111111111111111111111111111111111111111111111111111");
  38. }
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000036893488147419103231