fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. char c;
  5. unsigned int dec = 0, i = 1;
  6.  
  7. char bits[32];
  8. int bit_corrente = 0;
  9. while ((c = getchar()) != '\n') {
  10. bits[bit_corrente++] = c - '0';
  11. }
  12.  
  13. int j;
  14. for (j = bit_corrente - 1;j >= 0; --j){
  15. if (bits[j] == 1){
  16. dec += i;
  17. }
  18. i *= 2;
  19. }
  20.  
  21. printf("%d\n", dec);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 9424KB
stdin
11111110
stdout
254