We can write this program (to convert an integer number represented as string to BCD code) in C++ as;
Integer number (string) to BCD code using C++
#include <iostream> Â
#include <string> Â
using namespace std; Â
int binaryToDecimal(string n) Â
{ Â
string num = n; Â
int dec_value = 0; Â
int base = 1; Â // Initializing base value to 1, i.e 2^0
int len = num.length(); Â
for (int i = len - 1; i >= 0; i--) { Â
 if (num[i] == '1') Â
 dec_value += base; Â
base = base * 2; Â
} Â
return dec_value; Â
} Â