Skip to content

Conversation

@SONIYAPATIDAR
Copy link

#include
#include <math.h>
using namespace std;
int base2tobase10(int n){
int count=0, ans=0 ,rem ;
while(n!=0){
rem=n%10;
ans+=pow(2,count)*rem;
count++;
n/=10;

}
return ans;

}

int main(){
int n;
cout<<"Enter a decimal number : ";
cin>>n;
cout<<"Binary number of "<<n<<" is "<<base10tobase2(n)<<endl;

return 0;

}

@SONIYAPATIDAR
Copy link
Author

#include
#include <math.h>
using namespace std;

int base2tobase10(int n){
int count=0, ans=0 ,rem ;
while(n!=0){
rem=n%10;
ans+=pow(2,count)*rem;
count++;
n/=10;

}
return ans;

}

int main(){
int n;

cout<<"Enter a binary number : ";
cin>>n;
cout<<"Decimal number of "<<n<<" is "<<base2tobase10(n);

return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant