def twos_complement(val: int, bits: int) -> int:
    """
    returns the two's complement
    of the integer passed in.
    bits arg needed to determine the first bit
    """
    if (val & (1 << (bits - 1))) != 0:
        val = val - (1 << bits)
    return val