Use std::bitset to present the binary number. Then just use the std::bitset::to_ulong() member function to get the decimal value.
Example:
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
#include <string>
#include <bitset>
int main()
{
std::string s("100"); // 100 in binary is 4 in decimal
// Note: You have to specify exactly how many bits you need
std::bitset<sizeof(int) * 8> b(s);
std::cout << b.to_ulong() << '\n';
return 0;
}
Or have a look at the C function itoa(), but have in mind that it's non-standard, which means that not every implementation supports it.
I have created this function that should work, but it takes a string as binary number:
//returns -1 if the string is empty or the string contains other digits (chars) than 0 or 1
EDIT: You have at least to know how to convert mathematically a binary number to a decimal one ;)
EDIT: I have changed something: i had written this function when I was tired and I forgot one thing, but now it's returning -1, if it can't convert the string representing the binary number to the decimal one (because the string contains other digits than 1 or 0)