def twos_complement(value: int) -> int:
    """
    This method returns the 16-bit two's complement of a positive number
    (used for sending negative values to the controller). It raises an error
    if the argument is too large or is negative.
    """
    assert value.bit_length() <= 16, "Value too large!"
    assert value > 0, "Value is negative!"
    return (2 ** 16) - value