Given a string of hex characters, I want to create a byte array from these. E.g. Given the string "1A2B3C", I want my array to contain 0x1A, 0x2B, 0x3C.
I have it working using the code below, but would like to see a more efficient way of doing this.
(Checks for string length etc have been done by this point).
// Go through the string
int k = 0;
stringstream s;
for (int i = 0; i < STRING_SIZE; i++)
{
// Get 2 digits at a time and store in a temp variable
s.str("");
s << key[k++];
s << key[k++];
char temp[2];
memcpy(temp, s.str().c_str(), 2);
// Get the hex value and store in final array
actualArray[i] = (unsigned char)strtol(temp, 0, 16);
}