def twos_complement_to_int(val, length=4):
    """
    Two's complement representation to integer.

    We assume that the number is always negative.

    1. Invert all the bits through the number
    2. Add one
    """
    invertor = int('1' * length, 2)

    return -((int(val, 2) ^ invertor) + 1)