def operator_ixor(size): a = Array(size, 'int32') b = Array(size, 'int32') for i in range(size): a[i] = nb_types.int32(i) b[i] = nb_types.int32(size-i-1) operator.ixor(a, b) return a
def test_inplace(self): #operator = self.module class C(object): def __iadd__ (self, other): return "iadd" def __iand__ (self, other): return "iand" def __ifloordiv__(self, other): return "ifloordiv" def __ilshift__ (self, other): return "ilshift" def __imod__ (self, other): return "imod" def __imul__ (self, other): return "imul" def __ior__ (self, other): return "ior" def __ipow__ (self, other): return "ipow" def __irshift__ (self, other): return "irshift" def __isub__ (self, other): return "isub" def __itruediv__ (self, other): return "itruediv" def __ixor__ (self, other): return "ixor" def __getitem__(self, other): return 5 # so that C is a sequence c = C() self.assertEqual(operator.iadd (c, 5), "iadd") self.assertEqual(operator.iand (c, 5), "iand") self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv") self.assertEqual(operator.ilshift (c, 5), "ilshift") self.assertEqual(operator.imod (c, 5), "imod") self.assertEqual(operator.imul (c, 5), "imul") self.assertEqual(operator.ior (c, 5), "ior") self.assertEqual(operator.ipow (c, 5), "ipow") self.assertEqual(operator.irshift (c, 5), "irshift") self.assertEqual(operator.isub (c, 5), "isub") self.assertEqual(operator.itruediv (c, 5), "itruediv") self.assertEqual(operator.ixor (c, 5), "ixor") self.assertEqual(operator.iconcat (c, c), "iadd")
def put_(self, args): """PUT: Put a sprite on the screen.""" if self._mode.is_text_mode: raise error.BASICError(error.IFC) x0, y0 = (values.to_single(_arg).to_value() for _arg in islice(args, 2)) array_name, operation_token = args array_name = self._memory.complete_name(array_name) operation_token = operation_token or tk.XOR if array_name not in self._memory.arrays: raise error.BASICError(error.IFC) elif array_name[-1:] == values.STR: raise error.BASICError(error.TYPE_MISMATCH) x0, y0 = self._get_window_physical(x0, y0) self._last_point = x0, y0 packed_sprite = self._memory.arrays.view_full_buffer(array_name) sprite = self._mode.sprite_builder.unpack(packed_sprite) x1, y1 = x0 + sprite.width - 1, y0 + sprite.height - 1 # the whole sprite must fit or it's IFC error.throw_if(not self.graph_view.contains(x0, y0)) error.throw_if(not self.graph_view.contains(x1, y1)) # apply the sprite to the screen if operation_token == tk.PSET: rect = sprite elif operation_token == tk.PRESET: rect = sprite ^ (2**self._mode.bitsperpixel - 1) elif operation_token == tk.AND: # we use in-place operations as we'll assign back anyway rect = operator.iand(self.graph_view[y0:y1+1, x0:x1+1], sprite) elif operation_token == tk.OR: rect = operator.ior(self.graph_view[y0:y1+1, x0:x1+1], sprite) elif operation_token == tk.XOR: rect = operator.ixor(self.graph_view[y0:y1+1, x0:x1+1], sprite) self.graph_view[y0:y1+1, x0:x1+1] = rect
def _fold_md(self, data): """ This is a utility function that implements the folding algorithm in RFC 2289 for MD4 and MD5. """ result = bytearray() for x in range(8): result.append(operator.ixor(data[x], data[x + 8])) return result
def test_inplace(self): #operator = self.module class C(object): def __iadd__(self, other): return "iadd" def __iand__(self, other): return "iand" def __ifloordiv__(self, other): return "ifloordiv" def __ilshift__(self, other): return "ilshift" def __imod__(self, other): return "imod" def __imul__(self, other): return "imul" def __ior__(self, other): return "ior" def __ipow__(self, other): return "ipow" def __irshift__(self, other): return "irshift" def __isub__(self, other): return "isub" def __itruediv__(self, other): return "itruediv" def __ixor__(self, other): return "ixor" def __getitem__(self, other): return 5 # so that C is a sequence c = C() self.assertEqual(operator.iadd(c, 5), "iadd") self.assertEqual(operator.iand(c, 5), "iand") self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv") self.assertEqual(operator.ilshift(c, 5), "ilshift") self.assertEqual(operator.imod(c, 5), "imod") self.assertEqual(operator.imul(c, 5), "imul") self.assertEqual(operator.ior(c, 5), "ior") self.assertEqual(operator.ipow(c, 5), "ipow") self.assertEqual(operator.irshift(c, 5), "irshift") self.assertEqual(operator.isub(c, 5), "isub") self.assertEqual(operator.itruediv(c, 5), "itruediv") self.assertEqual(operator.ixor(c, 5), "ixor") self.assertEqual(operator.iconcat(c, c), "iadd")
def test_class_binary_inplace_operators(self): class WithLotsOfOperators(Class): def __iadd__(self, other): return (self, "iadd", other) def __isub__(self, other): return (self, "isub", other) def __imul__(self, other): return (self, "imul", other) def __imod__(self, other): return (self, "imod", other) def __itruediv__(self, other): return (self, "itruediv", other) def __ifloordiv__(self, other): return (self, "ifloordiv", other) def __ilshift__(self, other): return (self, "ilshift", other) def __irshift__(self, other): return (self, "irshift", other) def __ior__(self, other): return (self, "ior", other) def __iand__(self, other): return (self, "iand", other) def __ixor__(self, other): return (self, "ixor", other) def __imatmul__(self, other): return (self, "imatmul", other) c = WithLotsOfOperators() self.assertEqual(operator.iadd(c, 0), (c, "iadd", 0)) self.assertEqual(operator.isub(c, 0), (c, "isub", 0)) self.assertEqual(operator.imul(c, 0), (c, "imul", 0)) self.assertEqual(operator.imod(c, 0), (c, "imod", 0)) self.assertEqual(operator.itruediv(c, 0), (c, "itruediv", 0)) self.assertEqual(operator.ifloordiv(c, 0), (c, "ifloordiv", 0)) self.assertEqual(operator.ilshift(c, 0), (c, "ilshift", 0)) self.assertEqual(operator.irshift(c, 0), (c, "irshift", 0)) self.assertEqual(operator.ior(c, 0), (c, "ior", 0)) self.assertEqual(operator.iand(c, 0), (c, "iand", 0)) self.assertEqual(operator.ixor(c, 0), (c, "ixor", 0)) self.assertEqual(operator.imatmul(c, 0), (c, "imatmul", 0))
a = 8 b = operator.iand(a, 1) print a print b #将与自身的值相或的值赋给自身 同 |= #但是不改变自身的值,返回值返回相或的结果 a = 8 b = operator.ior(a, 1) print a print b #将与自身的值相异或的值赋给自身 同 ^= #但是不改变自身的值,返回值返回相异或的结果 a = 8 b = operator.ixor(a, 1) print a print b #将与自身相除取整的值赋给自身 同 /= #但是不改变自身的值,返回值返回相除的结果 a = 9 b = operator.idiv(a, 4) print a print b #将与自身相除取整的值赋给自身 同 //= #但是不改变自身的值,返回值返回相除的结果 a = 9.04 b = operator.ifloordiv(a, 4) print a
def bitwise_ixor_usecase(x, y): return operator.ixor(x, y)
b = 8 print(operator.itruediv(a, b)) """6.imod()- This function is used to assign and return remainder. This operation does “a%=b” operation. Assigning is not performed in case of immutable containers, such as strings, numbers and tuples.""" a = 3 b = 2 print(operator.imod(a, b)) """7. ixor() :- This function is used to assign and xor the current value. This operation does “a^ = b” operation. Assigning is not performed in case of immutable containers, such as strings, numbers and tuples.""" a = 1 b = 0 print(operator.ixor(a, b)) """8.ipow() :- This function is used to assign and exponentiate the current value. This operation does “a ** = b” operation. Assigning is not performed in case of immutable containers, such as strings, numbers and tuples.""" a = 3 b = 2 print(operator.ipow(a, b)) """9.iand() :- This function is used to assign and bitwise and the current value. This operation does “a &= b” operation. Assigning is not performed in case of immutable containers, such as strings, numbers and tuples""" a = 1 b = 1 print(operator.iand(a, b))
def __ixor__(self, other): return operator.ixor(self._wrapped(), other)
print("the string after concatenation is : ", end="") print(y) x = operator.isub(2, 3) print("the value after subtracting and assiging : ", end="") print(x) x = operator.imul(2, 3) print("the value after multiplying and assiging : ", end="") print(x) x = operator.itruediv(2, 3) print("the value after dividing and assign : ", end="") print(x) x = operator.ixor(10, 5) print("the value after xoring and assigning : ", end="") print(x) x = operator.ipow(5, 4) print("the value after exponentiating and assigning : ", end="") print(x) x = operator.ilshift(8, 2) print("the value after bitwise left shift and assigning : ", end="") print(x) x = operator.irshift(8, 2) print("the value after bitwise right shift and assigning : ", end="") print(x)
''' Created on Aug 12, 2018 @author: Subhashis ''' from operator import ixor if __name__ == '__main__': pass x=ixor(10.5,10.1)
a = 8 b = operator.iand(a,1) print a print b #将与自身的值相或的值赋给自身 同 |= #但是不改变自身的值,返回值返回相或的结果 a = 8 b = operator.ior(a,1) print a print b #将与自身的值相异或的值赋给自身 同 ^= #但是不改变自身的值,返回值返回相异或的结果 a = 8 b = operator.ixor(a,1) print a print b #将与自身相除取整的值赋给自身 同 /= #但是不改变自身的值,返回值返回相除的结果 a = 9 b = operator.idiv(a,4) print a print b #将与自身相除取整的值赋给自身 同 //= #但是不改变自身的值,返回值返回相除的结果 a = 9.04 b = operator.ifloordiv(a,4) print a
def update_event(self, inp=-1): self.set_output_val(0, operator.ixor(self.input(0), self.input(1)))
print(li) operator.delitem(li, slice(1, 4)) print(li) print(operator.getitem(li, slice(0, 2))) s1 = "testing " s2 = "operator" print(operator.concat(s1, s2)) if (operator.contains(s1, s2)): print("Contains") else: print("It doesn't") a = 1 b = 0 print(operator.and_(a, b)) print(operator.or_(a, b)) print(operator.invert(a)) x = 10 y = 5 print(operator.iadd(x, y)) print(operator.isub(x, y)) print(operator.iconcat(s1, s2)) print(operator.imul(x, y)) print(operator.itruediv(x, y)) print(operator.imod(x, y)) print(operator.ixor(x, y)) print(operator.ipow(x, y)) print(operator.iand(x, y)) print(operator.ior(x, y)) print(operator.ilshift(x, y)) print(operator.irshift(x, y))
# Working of ixor() and ipow() import operator x = 10 y = 5 # using ixor() to exclusive or and assign value x = operator.ixor(x, y) print("The value after xoring and assigning : ", end="") print(x) # using ipow() to exponentiate and assign value x = 5 y = 4 x = operator.ipow(x, y) print("The value after exponentiating and assigning : ", end="") print(x) # using ior() to or, and assign value x = 10 y = 5 x = operator.ior(x, y) print("The value after bitwise or, and assigning : ", end="") print(x) x = 5 y = 4 x = operator.iand(x, y) print("The value after bitwise and, and assigning : ", end="") print(x)