How to get an integer from a sequence of bytes
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon May 27 11:00:39 EDT 2013
On Mon, 27 May 2013 16:45:05 +0200, Mok-Kong Shen wrote:
> From an int one can use to_bytes to get its individual bytes, but how
> can one reconstruct the int from the sequence of bytes?
Here's one way:
py> n = 11999102937234
py> m = 0
py> for b in n.to_bytes(6, 'big'):
... m = 256*m + b
...
py> m == n
True
--
Steven
More information about the Python-list
mailing list