An alternative for python 2 and without a struct module would be:
>>> s = '\x61\x62\xff' >>> a = sum([ord(b) * 2**(8*n) for (b, n) in zip(s, range(len(s))[::-1])]) >>> print a 6382335
where the byte order is big-endian. This gives the same result as unutbu's answer:
>>> print struct.unpack('>I', '\x00' + s)[0] 6382335
To order the low byte, the conversion will be:
>>> a = sum([ord(b) * 2**(8*n) for (b, n) in zip(s, range(len(s)))]) >>> print a 16736865 >>> print struct.unpack('<I', s + '\x00')[0] 16736865
cvr
source share