Convert hexadecimal formatted ids to signed int64

def _convert_hex_str_to_int(val):
    """Convert hexadecimal formatted ids to signed int64"""
    if val is None:
        return None

    hex_num = int(val, 16)
    #  ensure it fits into 64-bit
    if hex_num > 0x7FFFFFFFFFFFFFFF:
        hex_num -= 0x10000000000000000

    assert -9223372036854775808 <= hex_num <= 9223372036854775807
    return hex_num