fork download
  1. #include <iostream>
  2.  
  3. int fromBin(int n)
  4. {
  5. int factor = 1;
  6. int total = 0;
  7.  
  8. while (n != 0)
  9. {
  10. total += (n%10) * factor;
  11. n /= 10;
  12. factor *= 2;
  13. }
  14.  
  15. return total;
  16. }
  17.  
  18. int main() {
  19. std::cout << fromBin(101010) << std::endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 4136KB
stdin
Standard input is empty
stdout
42