I have a hex string in cpp
std::string str = "fe800000000000000cd86d653903694b";
I want to convert it to a char array which stores it like this
unsigned char ch[16] = { 0xfe, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x0c, 0xd8, 0x6d, 0x65,
0x39, 0x03, 0x69, 0x4b };
I am thinking of traversing the string 2 characters at a time and storing it in a character array. But I was not able to find any library function that helps here.
for (size_t i = 0; i < str.length(); i += 2)
{
string part = hex.substr(i, 2);
//convert part to hex format and store it in ch
}
Any help is appreciated