本文整理汇总了Python中bitstring.BitArray.insert方法的典型用法代码示例。如果您正苦于以下问题:Python BitArray.insert方法的具体用法?Python BitArray.insert怎么用?Python BitArray.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitstring.BitArray
的用法示例。
在下文中一共展示了BitArray.insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ensure_padding
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import insert [as 别名]
def _ensure_padding(self, cipher_stream):
stream = BitArray(hex=cipher_stream)
stream_len = stream.len
while stream_len % 8:
stream.insert('0b0', 0)
stream_len = stream_len + 1
return stream
示例2: string_to_bitarray
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import insert [as 别名]
def string_to_bitarray(self, _string, _maxsize=448):
b = BitArray()
pos = 0
if (_string):
for c in _string:
c_str = "{:#09b}".format(ord(c))
print("{:s}:{:s}".format(c, c_str))
b.insert(c_str, pos)
pos += 7
if (len(b.bin) < _maxsize):
b.insert("{:#09b}".format(TERMINATOR), pos)
if (len(b.bin) > _maxsize):
raise Exception("Size of bit array exceeds the maximum size allowed ({:d}).".format(_maxsize))
return b
示例3: testInsert
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import insert [as 别名]
def testInsert(self):
s = BitArray("0b00")
s.insert("0xf", 1)
self.assertEqual(s, "0b011110")