fork download
  1. #include<iostream>
  2. #include<math.h>
  3. using namespace std;
  4. int main()
  5. {
  6. int n,b=0;
  7. cout<<"enter a binary no. ";
  8. cin>>n;
  9.  
  10. for(int i=0;n!=0;i++)
  11. {if (n%10)
  12. {b=b+pow(2,i);}
  13. n=n/10;
  14. }
  15.  
  16. cout<<b<<endl;
  17. }
Success #stdin #stdout 0.01s 5388KB
stdin
11101010101001
stdout
enter a binary no. 1023