binary data - How to pack integers of arbitrary size to byte buffer in Python -


the other way simple int(byte_buffer.encode('hex'), 16 )

but how convert integer byte_buffer.

the length stored prepending struct.pack('>i', len(byte_buffer)) value.

in 2.7 there int.bit_length() start, unfortunately must able run on 2.6.

this came with.

def int2str(i):     _bytes = list()     while > 0:         n = % 256         _bytes.insert(0, n)         = >> 8     return ''.join(struct.pack('b', x) x in _bytes) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -