Skip to content

Create convert binary to decimal.cpp#136

Open
SONIYAPATIDAR wants to merge 1 commit intoCoolRekha:mainfrom
SONIYAPATIDAR:patch-1
Open

Create convert binary to decimal.cpp#136
SONIYAPATIDAR wants to merge 1 commit intoCoolRekha:mainfrom
SONIYAPATIDAR:patch-1

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