Convert ASCII represented HEX into HEX
First you will need s short subroutine to convert each hex 4-bit nibble to binary, and then save off the nibbles as 8-bit binary values.

unsigned char hextobin (unsigned char digit)
{
    unsigned char value;

    if ((toupper(digit) &gt;= 'A')&amp;&amp;(toupper(digit) &lt;= 'F'))
    {
        value = (digit - 'A') + 10;
    }
    else if ((digit &gt;= '0') &amp;&amp; (digit &lt;= '9'))
    {
         value = digit - '0';
    }
    else
    {
         value = 255;    // error - not handling this below
    }
    return value;
}


Then for every two hex characters, call the above routine twice; for example if you are inputting them in a loop, somethig like this:

    unsigned char nibble1, nibble2, byte;

// assume inside a loop getting a characters from UART

{

    nibble1 = gethexchar();    // ssume gets one ASCII char 0-9 or A-F
    nibble2 = gethexchar();

    byte = 256 * hextobin(nibble1) + hextobin(nibble2);

    // can save byte off to buffer or write to file
}