Byte to integer conversion

Charles G Waldman cgw at fnal.gov
Thu Dec 16 14:57:24 EST 1999


Elefterios Stamatogiannakis writes:
 > 	How can i convert two, three, four bytes into an integer?
 > 
 > 	I know a way with pickle, using loads() but i wonder is there
 > a more elegant way of doing it.

>>> l = [1,2,3]
>>> reduce(lambda x,y: x*256+y, l)
66051

 > 	I don't care about big, little endian problems

If you sudenly start to care about this, you can just reverse/reorder
the list as needed.





More information about the Python-list mailing list