当前位置: 首页>>代码示例>>Python>>正文


Python BitArray.ror方法代码示例

本文整理汇总了Python中bitstring.BitArray.ror方法的典型用法代码示例。如果您正苦于以下问题:Python BitArray.ror方法的具体用法?Python BitArray.ror怎么用?Python BitArray.ror使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bitstring.BitArray的用法示例。


在下文中一共展示了BitArray.ror方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: speed_and_direction_packet

# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import ror [as 别名]
    def speed_and_direction_packet(address,
                                   speed,
                                   speed_steps,
                                   direction,
                                   headlight=False):
        """
        Build a speed and direction packet.

        param address int is the dcc device address.
        param speed   int is the speed. Depending on the
                      speed steps we make a baseline packet
                      or a 128-bit packet
        param direction int is 1 for forward and 0 for backwards.
        """
        address_bin = BitArray('uint:8=%d' % address)

        if speed_steps == 128:
            # Build a 2 byte advanced operation instruction
            instruction_bin1 = BitArray('0b00111111')
            instruction_bin2 = BitArray()
            if direction:
                instruction_bin2.append('0b1')
            else:
                instruction_bin2.append('0b0')
            speed_bin = BitArray('uint:7=%d' % speed)
            instruction_bin2.append(speed_bin)

            error = address_bin ^ instruction_bin1 ^ instruction_bin2
            data = [instruction_bin1, instruction_bin2, error]

        else:
            # Build a 1 byte direction and speed baseline packet
            instruction_bin = BitArray('0b01')
            if direction:
                instruction_bin.append('0b1')
            else:
                instruction_bin.append('0b0')
            if speed_steps == 14:
                if headlight:
                    instruction_bin.append('0b1')
                else:
                    instruction_bin.append('0b0')
                speed_bin = BitArray('uint:4=%d' % speed)
            else:
                speed_bin = BitArray('uint:5=%d' % speed)
                speed_bin.ror(1)

            instruction_bin.append(speed_bin)

            error = address_bin ^ instruction_bin
            data = [instruction_bin, error]

        return DCCGeneralPacket(address_bin, data)
开发者ID:hsanjuan,项目名称:dccpi,代码行数:55,代码来源:dcc_packet_factory.py

示例2: AHash

# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import ror [as 别名]
def AHash(k,p,bstream):
    block_size = int((k-1)*math.floor(math.log(p,2)))
    n_block = int(math.ceil(bstream.len/float(block_size)))
    message_size = block_size * n_block
    b0 = message_size

    #reset bitstream position
    bstream.pos = 0
    for i in range(1,n_block+1):
        try:
            b0 = roundHash(k, p, BitStream(bstream.read(block_size)), b0)
        except:
            padding_size = block_size - bstream.len%block_size
            b0 = roundHash(k, p,
                BitStream("0b" + bstream.read(bstream.len - bstream.pos).bin + "0" * padding_size),
                b0)

        if(i != n_block):
            tmp_b0 = BitArray("uint:" + str(int(math.ceil(math.log(p,2)))) + "=" + str(b0))
            tmp_b0.ror(int(math.ceil(math.log(p,2))//2))
            b0 = tmp_b0.uint

    return b0
开发者ID:Choestelus,项目名称:Elgamal-Messaging-System,代码行数:25,代码来源:Elgamal2557.py

示例3: testRor

# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import ror [as 别名]
 def testRor(self):
     s = BitArray("0b1000")
     s.ror(1)
     self.assertEqual(s, "0b0100")
开发者ID:juanrmn,项目名称:Arduino-Telescope-Control,代码行数:6,代码来源:test_bitarray.py


注:本文中的bitstring.BitArray.ror方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。