What is the best way to convert a variable length hex string e.g. \"01A1\"
to a byte array containing that data.
i.e converting this:
st
You said "variable length." Just how variable do you mean?
For hex strings that fit into an unsigned long I have always liked the C function strtoul
. To make it convert hex pass 16 as the radix value.
Code might look like:
#include
std::string str = "01a1";
unsigned long val = strtoul(str.c_str(), 0, 16);