fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int na10(string dana) {
  6. int pom=0;
  7. int dl=dana.length();
  8. for (int i=0; i<dl; i++) {
  9. int x=int(dana[dl-i-1]) - 48;
  10. pom=pom+x*pow(2, i);
  11. }
  12. return pom;
  13. }
  14. int main() {
  15. cout<<na10("101010")<<" , "<< na10("110101")<<endl;
  16. return 0;
  17. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
42 , 53