#include <stdio.h>
#include <stdint.h>

uint8_t * hexstr_to_bin(
    char const * str) {
 size_t const length = strlen(str);
 uint8_t * result =
    malloc((length + 1) / 2);
 size_t it;
 for (it = 0; it < length; ++it) {
  char const c = str[it];
  uint8_t const bin =
     (c > '9') ?
       (tolower(c) - 'a' + 10) : (c - '0');
  if (it % 2 == 0) {
   result[it / 2] = bin << 4;
  } else {
   result[it / 2] |= bin;
  }
 }
 return result;
}

int main(void) {
 free(hexstr_to_bin("a9"));
 return 0;
}