Hexadecimal to Integer


int hex2int(byte *arr, int start_position, int end_position) {
    int base = 1;
    int ret = 0;
    for(int i = end_position; i >= start_position; i--) {
        int val = 0;
        if (arr[i] >= 'A' && arr[i] <= 'F')
           val = 10 + (arr[i] - 'A');
        else if (arr[i] >= 'a' && arr[i] <= 'f')
           val = 10 + (arr[i] - 'a');
        else if (arr[i] >= '0' && arr[i] <= '9')
           val = arr[i] - '0';
           
        ret += val * base;
        base *= 16;
    }
    return ret;
}