def test_rshift(self): #operator = self.module self.assertRaises(TypeError, operator.rshift) self.assertRaises(TypeError, operator.rshift, None, 42) self.assertTrue(operator.rshift(5, 1) == 2) self.assertTrue(operator.rshift(5, 0) == 5) self.assertRaises(ValueError, operator.rshift, 2, -1)
def test_rshift(int_proxy: MagicProxy, str_proxy: MagicProxy): assert not int_proxy._hasError assert not str_proxy._hasError with pytest.raises(TypeError): operator.rshift(int_proxy, str_proxy) assert int_proxy._hasError assert str_proxy._hasError
def test_shifts_with_some_values(self, i: PythonValue, j: Optional[int]) -> None: TypeCheckLogger.clean_sing() new_val1 = i.lshift(pv.int(j)) new_val2 = i.rshift(pv.int(j)) assert not i.is_top() assert isinstance(i.val, AbstractValue) assert isinstance(new_val1.val, AbstractValue) assert isinstance(new_val2.val, AbstractValue) if i.val.is_top() or j is None: assert new_val1.val.is_top() assert new_val2.val.is_top() assert len(TypeCheckLogger().warnings) == 0 return if new_val1.val.is_top(): with raises(ValueError): ops.lshift(i.val.val, j) # type: ignore assert len(TypeCheckLogger().warnings) > 0 assert valueError.match(TypeCheckLogger().warnings[0][1]) else: assert ops.lshift(i.val.val, j) == new_val1.val.val # type: ignore if new_val2.val.is_top(): with raises(ValueError): ops.rshift(i.val.val, j) # type: ignore assert len(TypeCheckLogger().warnings) > 0 assert valueError.match(TypeCheckLogger().warnings[-1][1]) else: assert ops.rshift(i.val.val, j) == new_val2.val.val # type: ignore
def __irshift__(self, other): """ :see: `__rshift__` :rtype: Span """ operator.rshift(self, other) return self
def test_rshift_trace(self): trace = self.sdk.current_trace other_trace = self.sdk.current_trace span = Span.new(other_trace, Span.new_span_id()) operator.rshift(span, trace) self.assertIn(span, trace.spans) self.assertIn(span.span_id, trace.span_ids)
def test_rshift_span(self): span_id = Span.new_span_id() span_a = Span.new(self.trace, span_id) new_span_id = Span.new_span_id() span_b = Span.new(self.trace, new_span_id) operator.rshift(span_a, span_b) self.assertIs(span_a.parent_span_id, span_b.span_id)
def operator_rshift(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) return operator.rshift(a, b)
def main(): a = -1 b = 5.0 c = 2 d = 6 for k, v in {"a": a, "b": b, "c": c, "d": d}.items(): print(k + " =", v) print("\nPositive/Negative:") print("abs(a);", operator.abs(a)) print("neg(a);", operator.neg(a)) print("neg(b);", operator.neg(b)) print("pos(a);", operator.pos(a)) print("pos(b);", operator.pos(b)) print("\nArithmetic:") print("add(a, b) :", operator.add(a, b)) print("floordiv(a, b):", operator.floordiv(a, b)) print("floordiv(d, c):", operator.floordiv(d, c)) print("mod(a, b) :", operator.mod(a, b)) print("mul(a, b) :", operator.mul(a, b)) print("pow(c, d) :", operator.pow(c, d)) print("sub(b, a) :", operator.sub(b, a)) print("truediv(a, b) :", operator.truediv(a, b)) print("truediv(d, c) :", operator.truediv(d, c)) print("\nBitwise:") print("and_(c, d) :", operator.and_(c, d)) print("invert(c) :", operator.invert(c)) print("lshift(c, d):", operator.lshift(c, d)) print("or_(c, d) :", operator.or_(c, d)) print("rshift(d, c):", operator.rshift(d, c)) print("xor(c, d) :", operator.xor(c, d))
def parse_data(*, debug=False): prob_num = __file__[-5:-3] filename = int(prob_num) if debug: filename = f'{prob_num}.test' def to_int_maybe(v): try: return int(v) except: return v funcs = dict(AND=lambda a, b: and_(a, b) & 0xFFFF, OR=lambda a, b: or_(a, b) & 0xFFFF, LSHIFT=lambda a, b: lshift(a, b) & 0xFFFF, RSHIFT=lambda a, b: rshift(a, b) & 0xFFFF) def invert(v): return inv(v) & 0xFFFF def _get_circuit(l): left, right = l.split(' -> ') match left.split(): case ('NOT', x): left = invert, to_int_maybe(x) case x, cmd, y: left = funcs[cmd], to_int_maybe(x), to_int_maybe(y) case (x, ): left = to_int_maybe(x) case _: raise Exception('wth') return left, to_int_maybe(right) return [_get_circuit(l) for l in read_file(filename, 2015)]
def hash0(self, key): return operator.mod( int( operator.rshift( operator.xor(hash(key[1:]), int(hashlib.sha384(key).hexdigest(), 16)), 8)), self.m)
def fhook(self, ops, vm): check_num_args(self.name, ops, 3) check_reg_only(self.name, ops) fixed_op2 = ops[2].get_val() % 32 ops[0].set_val( check_overflow(opfunc.rshift(ops[1].get_val(), fixed_op2), vm)) vm.changes.add(ops[0].get_nm())
def parity(num): """Get parity of a binary encoded number.""" p = 0 while not num == 0: p = p + (num & 1L) num = rshift(num, 1) return p
def hash1(self, key): return operator.mod( int( operator.rshift( operator.xor( int(hashlib.md5(key[::-1]).hexdigest(), 16), int(hashlib.sha256(key[::-1]).hexdigest(), 16)), 15)), self.m)
def test_rshift(): """Test Number - correct initilization""" value = 42 num_a = param.Number(value=value) assert num_a.value == value new_value = operator.rshift(value, 1) num_a.value >>= 1 assert num_a.value == new_value
def fhook(self, ops, vm): val_one, val_two = get_stack_operands(vm) val_one_abs = abs(val_one) val_two_abs = abs(val_two) val_two_abs = val_two_abs % 32 # only for i32 result = opfunc.rshift(val_one_abs, val_two_abs) check_overflow(result, vm) vm.stack[hex(vm.get_sp()).split('x')[-1].upper()] = result vm.inc_sp()
def test_rshift(): """Test Integer - correct operation""" value = 42 num_a = param.Integer(value=value) assert num_a.value == value new_value = operator.rshift(value, 1) num_a.value >>= 1 assert num_a.value == new_value
def test_rshift(): """Test Parameter - correct initilization""" value = 42 num_a = param.Parameter(value=value) assert num_a.value == value new_value = operator.rshift(value, 1) num_a.value = num_a.__rshift__(1) assert num_a.value == new_value
def hash2(self, key): return operator.mod( int( operator.rshift( operator.xor( int(hashlib.md5(key[::-1]).hexdigest(), 16), hash(key + key[0:int(((1.0 * len(key)) - 0.5) / 2.0)])), 2)), self.m)
def _xr(self, a, b): size_b = len(b) c = 0 while c < size_b - 2: d = b[c + 2] d = ord(d[0]) - 87 if 'a' <= d else int(d) d = rshift(a, d) if '+' == b[c + 1] else a << d a = a + d & 4294967295 if '+' == b[c] else a ^ d c += 3 return a
def apply_operator_to_expressions(expression_operator, numerical_expressions): if expression_operator == "AND": return numerical_expressions[0] & numerical_expressions[1] elif expression_operator == "NOT": return ~numerical_expressions[0] elif expression_operator == "OR": return numerical_expressions[0] | numerical_expressions[1] elif expression_operator == "LSHIFT": return operator.lshift(numerical_expressions[0], numerical_expressions[1]) elif expression_operator == "RSHIFT": return operator.rshift(numerical_expressions[0], numerical_expressions[1]) return None
def fhook(self, ops, vm): check_num_args(self.name, ops, 2) check_reg_only(self.name, ops) result = ops[0].get_val() * ops[1].get_val() if result > 2**32 - 1: vm.registers['LO'] = opfunc.lshift(result, 32) vm.registers['HI'] = opfunc.rshift(result, 32) else: vm.registers['LO'] = result vm.registers['HI'] = 0 vm.changes.add('LO') vm.changes.add('HI') return ''
def add_rule(self, name, left, right, rate_forward, rate_reverse=None, *args, **kwargs): if len(left) == 0: left = None else: left = sum(left[1: ], left[0]) if len(right) == 0: right = None else: right = sum(right[1: ], right[0]) if rate_reverse is None: rule = operator.rshift(left, right) else: rule = operator.or_(left, right) return self.__add_rule(name, rule, rate_forward, rate_reverse, *args, **kwargs)
def binarize(in_col, out, width): """Convert any positive integer to a binary array. """ i = cuda.grid(1) if i < in_col.size: n = in_col[i] idx = width - 1 out[i, idx] = operator.mod(n, 2) idx -= 1 while n > 1: n = operator.rshift(n, 1) out[i, idx] = operator.mod(n, 2) idx -= 1
def process_line(filename): with open(filename, 'r') as f: lines = f.read().splitlines() for line in lines: words = line.split(' ') wire_name = CircuitBookletReader.give_wire(line) gate, index = CircuitBookletReader.give_gate(line) if gate == '': wire_signals[wire_name] = CircuitBookletReader.Signal(words[0]) if gate == 'NOT': if wire_name in list(wire_signals.keys()): wire_signals[wire_name].value = ~wire_signals[words[1]] else: wire_signals[wire_name] = CircuitBookletReader.Signal(~wire_signals[words[1]]) if gate == 'OR': if wire_name in list(wire_signals.keys()): wire_signals[wire_name].value = wire_signals[words[0]] | wire_signals[words[2]] else: wire_signals[wire_name] = CircuitBookletReader.Signal(wire_signals[words[0]] | wire_signals[words[2]]) if gate == 'AND': if wire_name in list(wire_signals.keys()): wire_signals[wire_name].value = wire_signals[words[0]] & wire_signals[words[2]] else: wire_signals[wire_name] = CircuitBookletReader.Signal(wire_signals[words[0]] & wire_signals[words[2]]) if gate == 'lshift': if wire_name in list(wire_signals.keys()): wire_signals[wire_name].value = operator.lshift(wire_signals[words[0]], int(words[2])) else: wire_signals[wire_name] = CircuitBookletReader.Signal(operator.lshift(wire_signals[words[0]], int(words[2]))) if gate == 'RSHIFT': if wire_name in list(wire_signals.keys()): wire_signals[wire_name].value = operator.rshift(wire_signals[words[0]], int(words[2])) else: wire_signals[wire_name] = CircuitBookletReader.Signal(operator.rshift(wire_signals[words[0]], int(words[2]))) pprint.pprint(wire_signals,indent=4)
def test_mult(self): for i in range(0, NUM_TESTS): a = random.randint(MIN_MUL, MAX_MUL) b = random.randint(MIN_MUL, MAX_MUL) correct = opfunc.mul(a, b) mips_machine.registers["R8"] = a mips_machine.registers["R9"] = b low_correct, high_correct = 0, 0 assemble("40000 MULT R8, R9", mips_machine) if correct > 2**32 - 1: low_correct = opfunc.lshift(correct, 32) high_correct = opfunc.rshift(correct, 32) else: low_correct = correct high_correct = 0 self.assertEqual(mips_machine.registers["HI"], high_correct) self.assertEqual(mips_machine.registers["LO"], low_correct)
def ecrire_texte(image, texte): """ Fonction qui permet d'écrire le texte dans les quartets R après le quartet N°7 (donc au 9ieme quartet) le 8 premiers qurtets sont réservés à la taille du texte """ N = 8 texte = "La prise du batiment se fera demain à 16h avec toutes les équipes!!!" liste_lettres = [] for i in texte: a0 = operator.and_(ord(i), 0b1111) # bits de poids faible de la lettre a1 = operator.rshift(operator.and_(ord(i), 0b11110000), 4) # bits de poids forts de la lettre liste_lettres.append(a1) liste_lettres.append(a0) print(liste_lettres) print(len(liste_lettres)) # ecrire les résultat dans les 4 bits de poids faible de cahque R de chaque pixel taille_liste_lettres = len(liste_lettres) print("liste lettre :", taille_liste_lettres) ############# Mise à zeros des quartets de poids faible de r cpt = 0 for y in range(1, 512): for x in range(0, 512): if cpt == taille_liste_lettres * 2 - 1: break r, g, b = image.getpixel((x, y)) r = operator.and_(r, 0b11110000) image.putpixel((x, y), (r, g, b)) cpt += 1 ####################### ecriture dans les quartets de poids faibles de R des lettres du texte cpt = 0 for y in range(1, 512): for x in range(0, 512): #print(x,y) if cpt == taille_liste_lettres: break r, g, b = image.getpixel((x, y)) r = operator.or_(liste_lettres[cpt], r) image.putpixel((x, y), (r, g, b)) cpt += 1 return image
def test_operator(self): """Programmatic link with operator.rshift/operator.lshift""" chainlets = [NamedChainlet(idx) for idx in range(10)] chain_full = _reduce(operator.rshift, chainlets) self.assertSequenceEqual(chain_full.elements, chainlets) chain_full_inv = _reduce(operator.lshift, chainlets) self.assertSequenceEqual(chain_full_inv.elements, list(reversed(chainlets))) link_chain = NeutralLink() call_chain = NeutralLink() for idx, link in enumerate(chainlets): prev_link_chain, prev_call_chain = link_chain, call_chain link_chain = link_chain >> link call_chain = operator.rshift(call_chain, link) self.assertEqual(link_chain, call_chain) # do not allow mutating existing chain self.assertNotEqual(link_chain, prev_link_chain) self.assertNotEqual(call_chain, prev_call_chain)
def ecrire_taille_texte(im, texte): """ image est une image du style image=Image.open('fichier.png') im : est une image sur laquelle on va aplliquer les changement im : résulte de Image.open('lena.png') texte : contient la chaine à cacher dans l'image """ N = 8 # nb de quartets réservés #taille=len(texte) # mise à zero des 8 premiers quartets rouges (R) im1 = lire_image(chemin, fichier) im2 = lire_image(chemin, fichier) ######### mise à zero des 8 premiers quartets R msq = 0b11110000 for i in range(N): r, g, b = im2.getpixel((i, 0)) im2.putpixel((i, 0), (operator.and_(r, msq), g, b)) ######### écriture de la longeur de la chaine dans les 8 premiers quartets R # longueur de la chaine dans la variable long long = len(texte) #long=3561 n_bits_long_chaine = len(bin(long)) - 2 # n_R représente le nombre de R utiles pour écrire la taille du texte # exemple si n_bits_long_chaine vaut 15, il faut 3 4 4 4 donc # R7 = xxxx 4 bits poids fort # R6 = xxxx 4 bits suivants # R5 = xxxx 4 bits suivants # R4 = xxxx x3 derniers bits nb_R = n_bits_long_chaine // 4 + 1 # nb quartets utiles # on commence par le R7 et on redescend vers R0 si besoin for i in range(N - 1, N - 1 - nb_R, -1): r, g, b = im2.getpixel((i, 0)) masque = operator.lshift(0b1111, 4 * (N - 1 - i)) nb = operator.and_(long, masque) nb = operator.rshift( nb, 4 * (N - 1 - i)) # on décale d'un multiple de 4 bits pour chaque valeur r = operator.or_(r, nb) im2.putpixel((i, 0), (r, g, b)) return im2
def eval(self, p4_state): # z3 does not like to shift operators of different size # but casting both values could lead to missing an overflow # so after the operation cast the lvalue down to its original size lval_expr = p4_state.resolve_expr(self.lval) rval_expr = p4_state.resolve_expr(self.rval) if isinstance(lval_expr, int): # if x is an int we might get a signed value # we need to use the arithmetic right shift in this case return op.rshift(lval_expr, rval_expr) # align the bitvectors to allow operations lval_is_bitvec = isinstance(lval_expr, z3.BitVecRef) rval_is_bitvec = isinstance(rval_expr, z3.BitVecRef) orig_lval_size = lval_expr.size() if lval_is_bitvec and rval_is_bitvec: if lval_expr.size() < rval_expr.size(): lval_expr = z3_cast(lval_expr, rval_expr.size()) if lval_expr.size() > rval_expr.size(): rval_expr = z3_cast(rval_expr, lval_expr.size()) return z3_cast(z3.LShR(lval_expr, rval_expr), orig_lval_size)
def run301_03(): """ arithmetic ops :return: """ a = -1 b = 5.0 c = 2 d = 6 print('a =', a) print('b =', b) print('c =', c) print('d =', d) print('\nPositive/Negative:') print('abs(a):', abs(a)) print('neg(a):', neg(a)) print('neg(b):', neg(b)) print('pos(a):', pos(a)) print('pos(b):', pos(b)) print('\nArithmetic:') print('add(a, b) :', add(a, b)) print('floordiv(a, b):', floordiv(a, b)) # for py2 print('floordiv(d, c):', floordiv(d, c)) # for py2 print('mod(a, b) :', mod(a, b)) print('mul(a, b) :', mul(a, b)) print('pow(c, d) :', pow(c, d)) print('sub(b, a) :', sub(b, a)) print('truediv(a, b) :', truediv(a, b)) print('truediv(d, c) :', truediv(d, c)) print('\nBitwise:') print('and_(c, d) :', and_(c, d)) print('invert(c) :', invert(c)) # ~c print('lshift(c, d):', lshift(c, d)) # c << d print('or_(c, d) :', or_(c, d)) print('rshift(d, c):', rshift(d, c)) # d >> c print('xor(c, d) :', xor(c, d)) # 不同得1 ^
def __init__(self, environment=Environment(), input=None): self.environment = environment self.environment.defineVariable("console", Console()) self.environment.defineVariable("Math", MathModule()) self.environment.defineVariable("Object", ObjectModule()) self.binaries = { '+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.truediv, '%': operator.mod, '<<': lambda x, y: float(operator.lshift(int(x), int(y))), '>>': lambda x, y: float(operator.rshift(int(x), int(y))), '>>>': lambda x, y: float((int(x) % 0x100000000) >> int(y)), '<': operator.lt, '>': operator.gt, '<=': operator.le, '>=': operator.ge, '==': operator.eq, '!=': operator.ne, '===': lambda x, y: type(x) == type(y) and x == y, '!==': lambda x, y: type(x) != type(y) or x != y, '||': lambda x, y: x or y, '&&': lambda x, y: x and y } self.unaries = { '-': operator.neg, '+': operator.pos, '~': lambda x: float(~int(x)), '!': operator.not_, '++': lambda x: x.__add__(1), '--': lambda x: x.__add__(-1) } self.assignment = { '=': lambda x, y: y, '+=': operator.iadd, '-=': operator.isub, '*=': operator.mul, '/=': operator.truediv }
def operator_arithmetic(): """ arithmetic, math +, -, |a| +, -, *, //, /, %, pow &, |, ^, ~, <<, >> """ a, b, c, d = -1, 5.0, 2, 6 print('a =', a) print('b =', b) print('c =', c) print('d =', d) print('\nPositive/Negative:') print('abs(a):', operator.abs(a)) print('neg(a):', operator.neg(a)) print('neg(b):', operator.neg(b)) print('pos(a):', operator.pos(a)) print('pos(b):', operator.pos(b)) print('\nArithmetic:') print('add(a, b) :', operator.add(a, b)) print('sub(b, a) :', operator.sub(b, a)) print('mul(a, b) :', operator.mul(a, b)) print('truediv(a, b) :', operator.truediv(a, b)) print('truediv(d, c) :', operator.truediv(d, c)) print('floordiv(a, b) :', operator.floordiv(a, b)) print('pow(c, d) :', operator.pow(c, d)) print('mod(a, b) :', operator.mod(a, b)) print('\nBitwise:') print('and_(c, d) :', operator.and_(c, d)) # c & d print('or_(c, d) :', operator.or_(c, d)) # c | d print('invert(c) :', operator.invert(c)) # two's complement. ~c = -c - 1 print('xor(c, d) :', operator.xor(c, d)) # a ^ b print('lshift(c, d) :', operator.lshift(c, d)) # d << c print('rshift(d, c) :', operator.rshift(d, c)) # d >> c
def __init__(self, environment = Environment(), input=None): self.environment = environment self.environment.defineVariable("console", Console()) self.environment.defineVariable("Math", MathModule()) self.environment.defineVariable("Object", ObjectModule()) self.binaries = { '+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.truediv, '%': operator.mod, '<<': lambda x, y: float(operator.lshift(int(x), int(y))), '>>': lambda x, y: float(operator.rshift(int(x), int(y))), '>>>': lambda x, y: float((int(x) % 0x100000000) >> int(y)), '<': operator.lt, '>': operator.gt, '<=': operator.le, '>=': operator.ge, '==': operator.eq, '!=': operator.ne, '===': lambda x, y: type(x) == type(y) and x == y, '!==': lambda x, y: type(x) != type(y) or x != y, '||': lambda x, y: x or y, '&&': lambda x, y: x and y } self.unaries = { '-': operator.neg, '+': operator.pos, '~': lambda x: float(~int(x)), '!': operator.not_, '++': lambda x: x.__add__(1), '--': lambda x: x.__add__(-1)} self.assignment = { '=': lambda x, y: y, '+=': operator.iadd, '-=': operator.isub, '*=': operator.mul, '/=': operator.truediv}
def rshift(a, b): return operator.rshift(a, b)
#~a = (-a)-1 #~10 = -11 #~(-10) = 9 print operator.inv(10) print operator.inv(-10) print operator.invert(10) print operator.invert(-10) #乘方 同a**b print operator.pow(2,3) #向左移位 同<< 相当于乘以2的相应次方 print operator.lshift(3,2) #向右移位 同>> 相当于除以2的相应次方 取整 print operator.rshift(3,2) #按位与 即 a&b print operator.and_(1,8) print operator.and_(1,1) #按位或 即 a|b print operator.or_(1,8) print operator.or_(1,3) #按位异或 即 a^b print operator.xor(1,8) print operator.xor(1,3) #合并,不过只能用于序列 print operator.concat([1,2],[3,4])
def bitshift_right_usecase(x, y): return operator.rshift(x, y)
import operator
def guarded_rshift(a, b): if not (isinstance(a, int) and isinstance(b, int)): raise CalcError("non-integer shift values") return op.rshift(a, b)
def test_rshift(self): self.failUnlessRaises(TypeError, operator.rshift) self.failUnlessRaises(TypeError, operator.rshift, None, 42) self.failUnless(operator.rshift(5, 1) == 2) self.failUnless(operator.rshift(5, 0) == 5) self.assertRaises(ValueError, operator.rshift, 2, -1)
# that is, 2^3^2 = 2^(3^2), not (2^3)^2. factor = Forward() factor << atom + ZeroOrMore( ( expop + factor ).setParseAction( pushFirst ) ) term = factor + ZeroOrMore( ( multop + factor ).setParseAction( pushFirst ) ) expr << term + ZeroOrMore( ( addop + term ).setParseAction( pushFirst ) ) bnf = expr return bnf # map operator symbols to corresponding arithmetic operations epsilon = 1e-12 opn = { "+" : operator.add, "-" : operator.sub, "*" : operator.mul, "/" : operator.truediv, ">>" : lambda x,y: operator.rshift(int(x),int(y)), "<<" : lambda x,y: operator.lshift(int(x),int(y)), "|" : lambda x,y: operator.or_(int(x),int(y)), "&" : lambda x,y: operator.and_(int(x),int(y)), "^" : operator.pow } fn = { "sin" : math.sin, "cos" : math.cos, "tan" : math.tan, "abs" : abs, "trunc" : lambda a: int(a), "round" : round, "sgn" : lambda a: abs(a)>epsilon and cmp(a,0) or 0} def evaluateStack( s ): op = s.pop() if op == 'unary -': return -evaluateStack( s )
def __rrshift__(self, y): return NonStandardInteger(operator.rshift(y, self.val))
print operator.neg(True) print operator.neg(False) print operator.or_(1, 2) print operator.or_(4, 3) print operator.or_(5, 2) print operator.pos(5) print operator.pos(-5) print operator.pos(True) print operator.pos(False) print operator.pow(2, 2) print operator.pow(5, 3) print operator.rshift(5, 2) print operator.rshift(-5, 3) print operator.sub(4, 2) print operator.sub(2, 4) print operator.sub(-4, 2) print operator.xor(4, 2) print operator.xor(8, 5) print operator.concat("he", "llo") print operator.concat([1,2,3,4], [5,6,7]) print operator.concat((1,2), (3,4)) l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9] s = "hello world"
def rshift(x, y): return operator.rshift(x, y) @binary('and_', '&')
def ursh(op1, op2): op1 = (op1 & 0xffffffff) # coerce to 32-bit int return operator.rshift(op1, op2) # Python .rshift does 0 fill
def __Cidr2Netmask(self, cidr): """ convert one byte of CIDR to netmask value """ number = 0 for i in range(cidr): number = number + operator.rshift(128, i) return number
def op_rshift(x,y): return _op.rshift(x,y) @cutype("(a,a) -> a")
('and', operator.and_), ('rand', lambda a, b: operator.and_(b, a)), ('floordiv', operator.floordiv), ('rfloordiv', lambda a, b: operator.floordiv(b, a)), ('lshift', operator.lshift), ('rlshift', lambda a, b: operator.lshift(b, a)), ('mod', operator.mod), ('rmod', lambda a, b: operator.mod(b, a)), ('mul', operator.mul), ('rmul', lambda a, b: operator.mul(b, a)), ('or', operator.or_), ('ror', lambda a, b: operator.or_(b, a)), ('pow', operator.pow), ('rpow', lambda a, b: operator.pow(b, a)), ('rshift', operator.rshift), ('rrshift', lambda a, b: operator.rshift(b, a)), ('sub', operator.sub), ('rsub', lambda a, b: operator.sub(b, a)), ('truediv', operator.truediv), ('rtruediv', lambda a, b: operator.truediv(b, a)), ('xor', operator.xor), ('rxor', lambda a, b: operator.xor(b, a)), ) _IBINOPS = ( ('iadd', operator.iadd), ('iand', operator.iand), ('ifloordiv', operator.ifloordiv), ('ilshift', operator.ilshift), ('imod', operator.imod),