/* Convert a hexadecimal characters to a number (0..15)  */
static uint8_t hex_char_to_num(char hex)
/* Convert a hexadecimal characters to a number (0..15)  */
static uint8_t hex_char_to_num(char hex)
{
    if(hex >= '0' && hex <= '9') {
        return hex - '0';
    }
    if(hex >= 'a') hex -= 'a' - 'A';
    switch(hex) {
        case 'A':
            return 10;
        case 'B':
            return 11;
        case 'C':
            return 12;
        case 'D':
            return 13;
        case 'E':
            return 14;
        case 'F':
            return 15;
        default:
            return 0;
    }
    return 0;
}