How do I write a long integer as binary in Python?

后端 未结 9 1216
梦谈多话
梦谈多话 2021-01-12 06:20

In Python, long integers have unlimited precision. I would like to write a 16 byte (128 bit) integer to a file. struct from the standard library supports only u

9条回答
  •  不知归路
    2021-01-12 06:59

    You could pickle the object to binary, use protocol buffers (I don't know if they allow you to serialize unlimited precision integers though) or BSON if you do not want to write code.

    But writing a function that dumps 16 byte integers by shifting it should not be so hard to do if it's not time critical.

提交回复
热议问题