fork(5) download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4.  
  5. int main()
  6. {
  7. char bin[100];
  8. unsigned long dec = 0;
  9. int i = 0;
  10. int s;
  11. fgets( bin, sizeof(bin), stdin);
  12. s = strlen( bin );
  13. while( s-- ) {
  14. if( bin[s] == '0' || bin[s] == '1' ) {
  15. dec = dec + pow(2, i++) * (bin[s] - '0');
  16. }
  17. };
  18. printf("\nDecimal Equivalent of Binary Number: \t %u\n", dec);
  19. return 0;
  20. }
Success #stdin #stdout 0s 2172KB
stdin
1000 0000   0000 0000   0000 0000 0000 0001
stdout
Decimal Equivalent of Binary Number: 	 2147483649