First of all I would like to say that this question is already related to this link (Convert ASCII string into Decimal and Hexadecimal Representations) but since I cannot add a comment, I need to ask something specific related to an answer on that thread.
The code from Jerry Coffin works for me:
for (int i=0; i<your_string.size(); i++)
std::cout << std::hex << (unsigned int)your_string[i] << " ";
but what I would like to do is instead of printing this out via cout, I would like to store it in an unsigned int variable because I need to pass this value to another function.
My code looks like this:
unsigned int Ascii2Hex(std::string sString2Convert)
{
unsigned int uiHexVal;
for (int i=0; i<sString2Convert.size(); i++)
{
uiHexVal << std::hex << (unsigned int)sString2Convert[i];
}
return (uiHexVal);
}
This obviously does not work because of the "<<" operator.
How can I work my way around this?