I'm not sure what you want. Numbers are stored in binary and you can use bitwise ops to do things with them. What kind of function are you actually looking for?
Ok, this is the kind of emplementation I want to end up with:
1 2 3 4 5 6 7 8 9 10 11 12
string conv_tobin(const string&)
{
string temps = "";
/*convert each character into a binary value, hopefully, if they are numbers they
will be treated like integers*/
/*convert this undefined binary type, which I assume is an integer
to a string.*/
/*Append the binary representation to the string*/
return temps;
}
converting the string into it's binary representation as a string.
string conv_str_tobin(const string& s)
{
string temps = "";
bitset<sizeof(s)> bin(string(s));
for(unsignedint x = 0; x < int(bin.size()); x++)
{
temps += conv<bool, string>(bin[x]);
}
return temps;
}
It wont compile NO MATTER WHAT.
bin.to_string() wont work.
bin.size() wont work
putting bin into a string stream all at once, or even bit-by-bit wont work.
I reasearched, etc.. etc...
I'm so close to just losing it over this thing.
common.cpp: In function 'std::string conv_str_tobin(const string&)':
common.cpp:133:16: error: request for member 'to_string' in 'bin', which is of non-class type 'std::bitset<4u>(std::string) {aka std::bitset<4u>(std::basic_string<char>)}'
return bin.to_string();
^
common.cpp:134:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^