本文整理匯總了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