DSA/algorithms/CPlusPlus/Number-system/binary_to_decimal.cpp

18 lines
299 B
C++
Raw Normal View History

#include<bits/stdc++.h>
using namespace std;
int binarytodecimal(int n){
int two=1,r,num=0;
while(n>0){
r=n%10;
num=num + two*r;
two*=2;
n/=10;
}
return num;
}
int main(){
int n;
cin>>n;
int decimal=binarytodecimal(n);
cout<<decimal;
}