def twos_complement(hexstr,bits):
    """
    twos_complement(hexstr,bits)

    Converts a hex string of a two's complement number to an integer

    Args:
        hexstr (str): The number in hex
        bits (int): The number of bits in hexstr

    Returns:
        int: An integer containing the number
    """
    value = int(hexstr,16)
    if value & (1 << (bits-1)):
        value -= 1 << bits
    return value