#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char *buf = "FE2A8D0000CA372D4F461B1D9A1883A32F018823FFFF60D30000484200000D0A0F270300030006000000B0040307000356A3";

static unsigned char hexNibble(const char *str)
{
    unsigned char hex = *str;
    if (hex >= 'a' && hex <='f')
    {
        hex -= ('a' - 10);
    }
    else if (hex >= 'A' && hex <= 'F')
    {
        hex -= ('A' - 10);
    }
    else if (hex >= '0' && hex <= '9')
    {
        hex -= '0';
    }
    else
    {
        hex = 0;
    }
    return hex;
}

static size_t createCharArrayFromHexString(char *result[], const char *str)
{
	size_t len = strlen(str);
	if (!len) return 0;
	size_t bytes = len / 2;
	int mostSignificantNibble = len % 2;
	size_t size = bytes + mostSignificantNibble;
	*result = malloc(size);
	char *out = *result;
	const char *in = str;
	if (mostSignificantNibble)
	{
		*out++ = hexNibble(in++);
	}
	while (bytes)
	{
		*out = hexNibble(in++);
		*out <<= 4;
		*out++ |= hexNibble(in++);
		--bytes;
	}
	return size;
}

int main(void) {
  int value = 0;
  char *converted;
  
  size_t convertedSize = createCharArrayFromHexString(&converted, buf);
  
  for (int i = 0; i < convertedSize; ++i)
  {
  	printf( "0x%02hhx\n", converted[i]);
  }
  
  free(converted);
}
