def hex_to_int(hex_string, signed=True):
    """Returns hex_string converted to int. Method can work with signed 2's complement any length.

    :param hex_string: hex string. Example 'DEADBEEF' or 'deadbeef'.
    :param signed: boolean. True or False, indicating if hex signed. Default True
    :return: int representation of hex_string
    """
    if signed:
        bits = len(bytearray.fromhex(hex_string)) * 8
        val = int('0x' + hex_string, 16)
        if val & 1 << bits - 1 != 0:
            val = val - (1 << bits)
        return val
    else:
        return int(hex_string, 16)
