fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. char number[1024];
  5. scanf("%1023s", number);
  6. int n = strlen(number);
  7. int novo = 0;
  8. for (int i = 0; i < n; i++) {
  9. novo += ((number[i] - '0') * (1 << (n - i - 1)));
  10. }
  11.  
  12. printf("%d", novo);
  13. }
Success #stdin #stdout 0s 9424KB
stdin
10101010
stdout
170