本文整理汇总了Python中operator.__rshift__方法的典型用法代码示例。如果您正苦于以下问题:Python operator.__rshift__方法的具体用法?Python operator.__rshift__怎么用?Python operator.__rshift__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.__rshift__方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __rshift__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __rshift__ [as 别名]
def __rshift__( self, n ):
'''
Right circular rotation of a BitVector through N positions can be
carried out by
bitvec >> N
This operator overloading is made possible by implementing the
__rshift__ method defined here. Note that this operator returns
the bitvector on which it is invoked. This allows for a chained
invocation of the operator.
'''
if self.size == 0:
raise ValueError('''Circular shift of an empty vector makes no sense''')
if n < 0:
return self << abs(n)
for i in range(n):
self.circular_rotate_right_by_one()
return self
示例2: shift_right_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __rshift__ [as 别名]
def shift_right_by_one(self):
'''
For a one-bit in-place right non-circular shift. Note that bitvector size
does not change. The rightmost bit that moves past the last element of the
bitvector is discarded and leftmost bit of the returned vector is set to
zero.
'''
size = len(self.vector)
right_most_bits = list(map( operator.__and__, self.vector, [0x8000]*size ))
self.vector = list(map( operator.__and__, self.vector, [~0x8000]*size ))
right_most_bits.insert(0, 0)
right_most_bits.pop()
self.vector = list(map(operator.__lshift__, self.vector, [1]*size))
self.vector = list(map( operator.__or__, self.vector, \
list(map(operator.__rshift__,right_most_bits, [15]*size))))
self._setbit(0, 0)
示例3: circular_rotate_left_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __rshift__ [as 别名]
def circular_rotate_left_by_one(self):
'For a one-bit in-place left circular shift'
size = len(self.vector)
bitstring_leftmost_bit = self.vector[0] & 1
left_most_bits = list(map(operator.__and__, self.vector, [1]*size))
left_most_bits.append(left_most_bits[0])
del(left_most_bits[0])
self.vector = list(map(operator.__rshift__, self.vector, [1]*size))
self.vector = list(map( operator.__or__, self.vector, \
list( map(operator.__lshift__, left_most_bits, [15]*size) )))
self._setbit(self.size -1, bitstring_leftmost_bit)
示例4: circular_rotate_right_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __rshift__ [as 别名]
def circular_rotate_right_by_one(self):
'For a one-bit in-place right circular shift'
size = len(self.vector)
bitstring_rightmost_bit = self[self.size - 1]
right_most_bits = list(map( operator.__and__,
self.vector, [0x8000]*size ))
self.vector = list(map( operator.__and__, self.vector, [~0x8000]*size ))
right_most_bits.insert(0, bitstring_rightmost_bit)
right_most_bits.pop()
self.vector = list(map(operator.__lshift__, self.vector, [1]*size))
self.vector = list(map( operator.__or__, self.vector, \
list(map(operator.__rshift__, right_most_bits, [15]*size))))
self._setbit(0, bitstring_rightmost_bit)
示例5: shift_left_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __rshift__ [as 别名]
def shift_left_by_one(self):
'''
For a one-bit in-place left non-circular shift. Note that bitvector size
does not change. The leftmost bit that moves past the first element of the
bitvector is discarded and rightmost bit of the returned vector is set to
zero.
'''
size = len(self.vector)
left_most_bits = list(map(operator.__and__, self.vector, [1]*size))
left_most_bits.append(left_most_bits[0])
del(left_most_bits[0])
self.vector = list(map(operator.__rshift__, self.vector, [1]*size))
self.vector = list(map( operator.__or__, self.vector, \
list(map(operator.__lshift__, left_most_bits, [15]*size))))
self._setbit(self.size -1, 0)
示例6: __rshift__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __rshift__ [as 别名]
def __rshift__( self, n ):
'For an in-place right circular shift by n bit positions.'
if self.size == 0:
raise ValueError('''Circular shift of an empty vector
makes no sense''')
if n < 0:
return self << abs(n)
for i in range(n):
self.circular_rotate_right_by_one()
return self