I had a similar problem. I passed a "hex"-argument from python to a c-binary, i.e. 568AD6E4338BD93479C210105CD4198B, like:
subprocess.getoutput("binary.exe 568AD6E4338BD93479C210105CD4198B")
In my binary I wanted the passed argument to be stored in a uint8_t hexarray[16], but instead of char value '5' (raw hex 0x35), I needed actual raw hex value 0x5... and 32 chars make up a 16 sized uint8_t array, thus bit shifting etc..
for (i=0;i<16;i++) {
if (argv[1][i*2]>0x40)
hexarray[i] = ((argv[1][i*2] - 0x37) << 4);
else
hexarray[i] = ((argv[1][i*2] - 0x30) << 4);
if (argv[1][i*2+1]>0x40)
hexarray[i] = hexarray[i] + (argv[1][i*2+1] - 0x37);
else
hexarray[i] = hexarray[i] + (argv[1][i*2+1] - 0x30);
This would only work for hexstrings with upper chars.