[Tutor] Problems with unsigned integers
kent37 at tds.net
Mon Dec 13 19:27:25 CET 2004
It seems that ntohl doesn't understand about unsigned values, at least on Win32:
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from struct import pack, unpack
>>> pack('L', -1)
>>> unpack('L', '\xff\xff\xff\xff')
>>> from socket import ntohl
Loptr Chaote wrote:
> Hello everyone!
> I'm having problems with signed/unsigned (32bit) integers in python.
> Example code:
> seq = 0L
> seq = socket.ntohl(struct.unpack("L", data[38:42]))
> print seq
> This sometimes produces a negative output, how is that possible since
> I booth initialized seq with "0L" and also specified "L" in unpack()?
> Tutor maillist - Tutor at python.org
More information about the Tutor