Just as a taste of what awaits you in the future when you get ready to tackle the STL, the same basic thing you are doing can be accomplished in a few simple steps using a bitset container:
Sample output:Code:#include <iostream> #include <bitset> #include <limits> #include <string> int main() { std::string data; std::cout << "Enter in a binary value to be converted to decimal: "; std::cin >> data; std::bitset<std::numeric_limits<long>::digits> bits(data); std::cout << "The converted decimal value is: " << bits.to_ulong() << std::endl; return 0; }
Enter in a binary value to be converted to decimal: 1101101
The converted decimal value is: 109
In the meantime, keep pluggin away at what you are doing.