Task: Write a Program To Convert Binary to Decimal Number in C++
Te Source code of C++ Program To Convert Binary to Decimal Number
// Write a C++ program to input a binary number, // and convert into correspondin Decimal number #include<iostream> #include<math.h> using namespace std; int main() { long int binNum,rem,n,i,decimal; cout<<"Enter a Binary Number:"; cin>>binNum; i=0; decimal=0; for(n=binNum;n!=0;n=n/10) { rem=n%10; decimal=decimal+rem*pow(2,i); i++; } cout<<"Decimal Number: "<<decimal; return 0; }
The Output of the C++ Program To input a Binary number and convert it into decimal number
Enter a Binary Number:101 Decimal Number: 5 -------------------------------- Process exited after 25.63 seconds with return value 0 Press any key to continue . . .