def get_2comp(val_int, val_size=16):
    """Get the 2's complement of Python int val_int

        :param val_int: int value to apply 2's complement
        :type val_int: int
        :param val_size: bit size of int value (word = 16, long = 32) (optional)
        :type val_size: int
        :returns: 2's complement result
        :rtype: int
    """
    # test MSBit (1 for negative)
    if (val_int&(1<<(val_size-1))):
        # do complement
        val_int = val_int - (1<<val_size)
    return val_int