Below is a very crappy program I quickly wrote recently to turn a list of two character groups into a raw binary. Within that program is the code to do what you want. I’m not saying it is the best way to do it, I’m not saying it’s the fastest way to do it, but it does work.
#include <stdio.h>
#include <stdlib.h>
void main(void)
{
FILE *inFile, *outFile;
char buff[80];
unsigned char outChar;
if (!(inFile = fopen("bms_firmware_2.txt", "r")))
{
printf("\nCOULD NOT OPEN INPUT!\n");
}
if (!(outFile = fopen("bms.bin", "wb")))
{
printf("\nCOULD NOT OPEN OUTPUT FILE!\n");
}
printf("\nStart of program\n");
while (!feof(inFile))
{
fgets(buff, 80, inFile);
printf(".");
if (buff[0] >= '0' && buff[0] <= '9') outChar = (buff[0] - '0') * 16;
else outChar = (buff[0] - 'a' + 10) * 16;
if (buff[1] >= '0' && buff[1] <= '9') outChar += (buff[1] - '0');
else outChar += (buff[1] - 'a' + 10);
fputc(outChar, outFile);
}
fclose(inFile);
fclose(outFile);
}