Binary to decimal

#include
#include
using namespace std;
int main(){
int n{};
cin>>n;
int i{1};
int ans;
while(true){
ans =ans+ (n%10 * pow(2,i)); //for getting last digit and multiplying with power 2
n=n/10;
if(n==0)
{
cout<<ans;
break;
}
else
++i;
}
return 0;
}