Would you expect there to be any difference in the values of a and b given this code:
s = "\x4f\x00\x00\x50\xae\x08\x00\x00"
a = map(lambda x:x & 0xffff, struct.unpack('HHHH', s))
b = map(lambda x:x, struct.unpack('HHHH', s))
in both cases they end up being this list:
[79, 20480, 2222, 0]
where each element is an int.
The reason I ask is that I’m looking at the source of tcp.py in pyip which includes essentially this code and the “& 0xffff” seems pointless – am I missing something?
The only time that “& 0xffff” makes a difference is when there are greater than 16 bits. Namely, performing the logical-and produces a value in which the bits more significant than the lower 16 are all set to zero.