Program for Binary to Decimal Conversion
www.programmingcalculator.com
https://nikhilnihal.github.io/programmingcalculator/index.html
C++ Program to Convert Binary To Decimal
#include<bits/stdc++.h>
using namespace std;
int main()
{
long bin, dec = 0, rem, num, base = 1;
cout << "Enter the binary number";
cin >> num;
bin = num;
while (num > 0)
{
rem = num % 10;
dec = dec + rem * base;
base = base * 2;
num = num / 10;
}
cout << "The decimal equivalent of " << bin << " : " << dec << endl;
return 0;
}
https://nikhilnihal.github.io/programmingcalculator/index.html
C++ Program to Convert Binary To Decimal
#include<bits/stdc++.h>
using namespace std;
int main()
{
long bin, dec = 0, rem, num, base = 1;
cout << "Enter the binary number";
cin >> num;
bin = num;
while (num > 0)
{
rem = num % 10;
dec = dec + rem * base;
base = base * 2;
num = num / 10;
}
cout << "The decimal equivalent of " << bin << " : " << dec << endl;
return 0;
}
Comments
Post a Comment