I have a string that represents an hexadecimal number:
std::string hex = "3371";
I want to convert it to a char array:
char hex[2] {0x33, 0x71};
Is there any convenient way to do it? I can use c++11 features, if it may help.
Motivation: I need to save an integer (4 bytes), using 2 bytes char array. The way how I thought it can be done is to convert it to string using std::hex, and then convert the string to the char array, but this is the point where I cannot continue.. If there is another simple way - I would like to hear :)
Important: I can assume that the hex number is less than 0xFFFF, and a positive number.