From 83edeac03ef23336e6f0c161e69680ef73cee13c Mon Sep 17 00:00:00 2001 From: SONIYAPATIDAR <110100877+SONIYAPATIDAR@users.noreply.github.com> Date: Tue, 18 Oct 2022 21:15:45 +0530 Subject: [PATCH] Create convert binary to decimal.cpp --- C++/convert binary to decimal.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 C++/convert binary to decimal.cpp diff --git a/C++/convert binary to decimal.cpp b/C++/convert binary to decimal.cpp new file mode 100644 index 0000000..545cd70 --- /dev/null +++ b/C++/convert binary to decimal.cpp @@ -0,0 +1,23 @@ +#include +#include +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 "<