#include
#include
using namespace std;
int main()
{ int n ;
cin>> n;
int m;
int sum=0;
int x;
for(int i=0; i!=n; i++)
{
x= n%10;
n=n/10;
m=x*pow(2,i);
sum=sum+m;
}
cout<< sum;
return 0;
}
PLEASE TELL THE MISTAKE IN MY CODE …
Binary to decimal
take the input as string not int as binary can be large
100111010101001 this int will not in int range
now simply run the loop
POSTED WRONG CODE BY MISTAKE
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.