What is a simple way to write a function that coverts a c++ std::string which is in hexadecimal format into a uint8_t array?
For example:
#include <cstdint.h> //for uint8_t
#include <cstring.h> //for size_t
uint8_t output[64];
std::string input("EC83515650243FC512269A59CE0A82F4D4C92CD09F6037026BAA1A56AA97EBCB");
int ret = 0;
ret = hexStrToByteArray(input, output, sizeof(output));
Bonus points if you use C++17.
I think the function hexStrToByteArray can be something like:
int hexStrToByteArray(std::string input, uint8_t * output, size_t outLen)
{
if(input.length()/2 != outLen)
{
return -1;
}
//TODO convert input into output
}
This seems like it should have already been answered on stack overflow, but I could only find answers that did the conversation in a c-like style or where the output was a vector instead of an array.