Advertisement

Python涉及二进制操作

阅读量:

Python bitstring模块介绍

复制代码
    pip install bitstring
    from bitstring import BitArray, BitStream
    a = BitArray('0xff01')
复制代码
    10<<10 # 15.2 ns 仅整数
    b'\x5f'.hex() # 111 ns
    '香香香'.encode() # 139 ns 仅字符串
    binascii.b2a_hex(b'\xb9\x01\xef') # 172 ns 仅字符串
    struct.pack('>i',65535) # 211 ns 仅符合C语言标准结构
    int('101',8) # 224 ns
    bytes.fromhex('ff ff ff') # 231 ns 仅hex字符
    int.to_bytes(1111,length=8,byteorder='little') # 260 ns 仅整数
    bytearray.fromhex('ff ff ff') # 282 ns 仅hex字符
    ctypes.string_at(i,g) # 1.13 µs 可以对

全部评论 (0)

还没有任何评论哟~