#include <stdio.h>
#include <string.h>
#define HEXSIZE 8
enum { ARRAYSIZE = HEXSIZE / 2 };
void hex_to_byte_array(const char hex[], unsigned char byteArray[]) {
int temp;
for (int i = 0; i < ARRAYSIZE; ++i) {
sscanf(hex + 2 * i, "%2x", &temp);
byteArray[i] = temp;
}
}
int main() {
const char hex[HEXSIZE] = "1E2D3E4F";
unsigned char byteArray[ARRAYSIZE] = "";
hex_to_byte_array(hex, byteArray);
for (size_t i = 0; i < 4; ++i) {
printf("%02X ", byteArray[i]);
}
return 0;
}
/*
run:
1E 2D 3E 4F
*/