當前位置: 首頁>>代碼示例>>Python>>正文


Python operator.rshift方法代碼示例

本文整理匯總了Python中operator.rshift方法的典型用法代碼示例。如果您正苦於以下問題:Python operator.rshift方法的具體用法?Python operator.rshift怎麽用?Python operator.rshift使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在operator的用法示例。


在下文中一共展示了operator.rshift方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: binary_repr

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def binary_repr(number, max_length = 1025):
    """
    Return the binary representation of the input *number* as a
    string.

    This is more efficient than using :func:`base_repr` with base 2.

    Increase the value of max_length for very large numbers. Note that
    on 32-bit machines, 2**1023 is the largest integer power of 2
    which can be converted to a Python float.
    """

    #assert number < 2L << max_length
    shifts = map (operator.rshift, max_length * [number], \
                  range (max_length - 1, -1, -1))
    digits = map (operator.mod, shifts, max_length * [2])
    if not digits.count (1): return 0
    digits = digits [digits.index (1):]
    return ''.join (map (repr, digits)).replace('L','') 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:21,代碼來源:mlab.py

示例2: set_bit_order

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def set_bit_order(self, order):
        """Set order of bits to be read/written over serial lines.  Should be
        either MSBFIRST for most-significant first, or LSBFIRST for
        least-signifcant first.
        """
        # Set self._mask to the bitmask which points at the appropriate bit to
        # read or write, and appropriate left/right shift operator function for
        # reading/writing.
        if order == MSBFIRST:
            self._mask = 0x80
            self._write_shift = operator.lshift
            self._read_shift = operator.rshift
        elif order == LSBFIRST:
            self._mask = 0x01
            self._write_shift = operator.rshift
            self._read_shift = operator.lshift
        else:
            raise ValueError('Order must be MSBFIRST or LSBFIRST.') 
開發者ID:adafruit,項目名稱:Adafruit_Python_GPIO,代碼行數:20,代碼來源:SPI.py

示例3: binary_repr

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def binary_repr(number, max_length = 1025):
    """
    Return the binary representation of the input *number* as a
    string.

    This is more efficient than using :func:`base_repr` with base 2.

    Increase the value of max_length for very large numbers. Note that
    on 32-bit machines, 2**1023 is the largest integer power of 2
    which can be converted to a Python float.
    """

    #assert number < 2L << max_length
    shifts = list(map (operator.rshift, max_length * [number], \
                  range (max_length - 1, -1, -1)))
    digits = list(map (operator.mod, shifts, max_length * [2]))
    if not digits.count (1): return 0
    digits = digits [digits.index (1):]
    return ''.join (map (repr, digits)).replace('L','') 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:21,代碼來源:mlab.py

示例4: binary_repr

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def binary_repr(number, max_length=1025):
    """
    Return the binary representation of the input *number* as a
    string.

    This is more efficient than using :func:`base_repr` with base 2.

    Increase the value of max_length for very large numbers. Note that
    on 32-bit machines, 2**1023 is the largest integer power of 2
    which can be converted to a Python float.
    """

#   assert number < 2L << max_length
    shifts = map(operator.rshift, max_length * [number],
                 range(max_length - 1, -1, -1))
    digits = list(map(operator.mod, shifts, max_length * [2]))
    if not digits.count(1):
        return 0
    digits = digits[digits.index(1):]
    return ''.join(map(repr, digits)).replace('L', '') 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:22,代碼來源:mlab.py

示例5: test_operatorerrors

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def test_operatorerrors(self):
        f2 = self.f2
        f2p = self.f2p
        f256 = self.f256
        f19 = self.f19
        self.assertRaises(TypeError, operator.add, f2(1), f2p(2))
        self.assertRaises(TypeError, operator.iadd, f2(1), f2p(2))
        self.assertRaises(TypeError, operator.sub, f2(1), f256(2))
        self.assertRaises(TypeError, operator.isub, f2(1), f256(2))
        self.assertRaises(TypeError, operator.mul, f2(1), f19(2))
        self.assertRaises(TypeError, operator.imul, f2(1), f19(2))
        self.assertRaises(TypeError, operator.truediv, f256(1), f19(2))
        self.assertRaises(TypeError, operator.itruediv, f256(1), f19(2))
        self.assertRaises(TypeError, operator.truediv, 3.14, f19(2))
        self.assertRaises(TypeError, operator.lshift, f2(1), f2(1))
        self.assertRaises(TypeError, operator.ilshift, f2(1), f2(1))
        self.assertRaises(TypeError, operator.lshift, 1, f2(1))
        self.assertRaises(TypeError, operator.rshift, f19(1), f19(1))
        self.assertRaises(TypeError, operator.irshift, f19(1), f19(1))
        self.assertRaises(TypeError, operator.irshift, f256(1), f256(1))
        self.assertRaises(TypeError, operator.pow, f2(1), f19(2))
        self.assertRaises(TypeError, operator.pow, f19(1), 3.14) 
開發者ID:lschoe,項目名稱:mpyc,代碼行數:24,代碼來源:test_finfields.py

示例6: test_operatorerrors

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def test_operatorerrors(self):
        secfld = sectypes.SecFld()
        secint = sectypes.SecInt()
        a = secfld(0)
        b = secint(1)
        self.assertRaises(TypeError, operator.add, a, b)
        self.assertRaises(TypeError, operator.add, a, 3.14)
        self.assertRaises(TypeError, operator.sub, a, b)
        self.assertRaises(TypeError, operator.mul, a, b)
        self.assertRaises(TypeError, operator.mul, 3.14, b)
        self.assertRaises(TypeError, operator.truediv, a, b)
        self.assertRaises(TypeError, operator.truediv, a, b)
        self.assertRaises(TypeError, operator.mod, a, b)
        self.assertRaises(TypeError, operator.mod, b, a)
        self.assertRaises(TypeError, operator.floordiv, a, b)
        self.assertRaises(TypeError, divmod, a, b)
        self.assertRaises(TypeError, divmod, b, a)
        self.assertRaises(TypeError, operator.pow, b, 3.14)
        self.assertRaises(TypeError, operator.lshift, b, 3.14)
        self.assertRaises(TypeError, operator.lshift, 3.14, b)
        self.assertRaises(TypeError, operator.rshift, b, 3.14)
        self.assertRaises(TypeError, operator.rshift, 3.14, b) 
開發者ID:lschoe,項目名稱:mpyc,代碼行數:24,代碼來源:test_sectypes.py

示例7: testRShift

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def testRShift(self):
        self.binaryCheck(operator.rshift, jmax=256) 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:4,代碼來源:test_Signal.py

示例8: __rshift__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def __rshift__(self, y):
    return NonStandardInteger(operator.rshift(self.val, y)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:4,代碼來源:test_util.py

示例9: __rrshift__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def __rrshift__(self, y):
    return NonStandardInteger(operator.rshift(y, self.val)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:4,代碼來源:test_util.py

示例10: test_rshift

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def test_rshift(self):
        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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_operator.py

示例11: _op_generic_SarN

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def _op_generic_SarN(self, args):
        return self.generic_shift_thing(args, operator.rshift) 
開發者ID:angr,項目名稱:angr,代碼行數:4,代碼來源:irop.py

示例12: __rshift__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def __rshift__(self, other):
        return self._bin_op(other, operator.rshift) 
開發者ID:angr,項目名稱:angr,代碼行數:4,代碼來源:dataset.py

示例13: __rshift__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def __rshift__(self, other):
        return self._op(other, operator.rshift) 
開發者ID:kdart,項目名稱:pycopia,代碼行數:4,代碼來源:UserFloat.py

示例14: __rrshift__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def __rrshift__(self, other):
        return self._rop(other, operator.rshift) 
開發者ID:kdart,項目名稱:pycopia,代碼行數:4,代碼來源:UserFloat.py

示例15: __rshift__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import rshift [as 別名]
def __rshift__(self, other):
        return self._o2(other, operator.rshift) 
開發者ID:Berserker66,項目名稱:omnitool,代碼行數:4,代碼來源:vec2d.py


注:本文中的operator.rshift方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。