ascii2dec

Uwe Mayer merkosh at hadiko.de
Wed Aug 20 13:48:27 EDT 2003


Uwe Mayer wrote:

> this must sound stupid to you, but I'm ages out of Python and I just can't
> find a function to convert 4 bytes of binary data to an integer value:
> 
> length=f.read(4)    # get length in binary
> length=socket.htonl(length)    # swap bytes
> 
> #convert 4 bytes to integer
 
Sorry, socket.htonl(...) already expects a number, so its:

> #convert 4 bytes to integer
> length=socket.htonl(length)    # swap bytes

i.e. 
How to convert:

length = '\x01\x00\x00\x00'

to an integer

Uwe
-- 
        




More information about the Python-list mailing list