C++ Programming Code Examples C++ > Conversions Code Examples Simple C++ program to convert binary decimal number Simple C++ program to convert binary decimal number Binary to Decimal Conversion Code in C++ Program Logic Explanation Dry run the code with a simple input so the basic working of program can be understand easily Write a C++ program which asks user to input a binary number then convert it into its equivalent decimal number and show the result. To improve readability of program make a separate function and function should return the resultant number. In main function user enters input number Calls the function and pass the number Function calculates the required result and return In main function program displays the final result #include<iostream> using namespace std; long ConvertBinary2Decimal(unsigned long num); int main() { unsigned long binary_num, decimal = 0; cout <<"\n\tEnter a binary number to get Equivalent Decimal : "; cin >> binary_num; decimal=ConvertBinary2Decimal(binary_num); cout <<"\n\tDecimal Value Of " <<binary_num << " is = " << decimal << endl; return 0; } long ConvertBinary2Decimal(unsigned long bin_num) { unsigned long decimal = 0; int remainder=0, base = 1; while (bin_num > 0) { remainder = bin_num % 10; decimal = decimal + remainder * base; bin_num = bin_num / 10; base = base * 2; } return decimal; }