Here is source code of the C++ program which converts the given binary number into decimal. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ program to convert binary number into decimal
using namespace std;
long bin, dec = 0, rem, num, base = 1;
cout << "Enter the binary number(1s and 0s) : ";
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;
$ g++ main.cpp $ ./a.out Enter the binary number(1s and 0s) : 10000000000 The decimal equivalent of 10000000000 : 1024
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.