Photo by Arnold Francisca on Unsplash
Code to convert Binary to Decimal
c++ code to convert binary to decimal
//binary to decimal
#include<iostream>
using namespace std;
int DecToBinary(int n ){
int p=1;
int ans =0;
int last_digit;
while (n!=0){
last_digit= n%10;
ans= ans + last_digit*p;
n=n/10;
p=p*2;
}
return ans;
}
int main(){
int N;
cin>>N;
cout<<DecToBinary(N)<<endl;
return 0;
}