/* 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)
{
    uint8_t result = 0;
    if(hex >= '0' && hex <= '9') {
        result = hex - '0';
    } else {
        if(hex >= 'a') hex -= 'a' - 'A';
        switch(hex) {
            case 'A': result = 10; break;
            case 'B': result = 11; break;
            case 'C': result = 12; break;
            case 'D': result = 13; break;
            case 'E': result = 14; break;
            case 'F': result = 15; break;
            default: result = 0; break;
        }
    }
    return result;
}