Write a recursive function (with no loops or static variables) named binToDec that takes a string object as a parameter. The string will consist of 1s and 0s, representing a binary number. The function should return an int giving the decimal equivalent. For example,
cout << binToDec("101010") << endl;
should print out 42.
We can calculate this conversion as 1*25 + 0*24 + 1*23 + 0*22 + 1*21 + 0*20. This is, incidentally, the same as how decimal numbers work, except the base is different. For example “1027” is 1*103 + 0*102 + 2*101 + 7*100.
Notice that the indices of the characters count in the opposite direction as the exponents do.
You may not use any built-in base-conversion functionality of C++.
You may write a helper function that meets the specifications and calls your recursive function with additional arguments.
You may use the string::substr() function if you want.