Binary to decimal

everyting good but when sumbit code show wrong ans i don’t know where mistake in this code please let me explain soon as possible

#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int i=1,ans=0;
while(n!=0){
int digit=n%10;
if(digit==1){
ans=ans+pow(2,i);

    }
    n=n/10;
    i++;
}
cout<<ans<<endl;
return 0;

}

hi @dheerajjha11111_bb855e8d7a52ef0d initialize i with 0 not 1