I have four bytes from a raw socket: value=0xc0ff00c0. Using struct with a format of L (or I for that matter) to unpack
struct.unpack("=L",value)
I get 3221290944. Using
int(hexlify(value),16)
I get 3237937344. The latter is correct. I have not noticed this with other format specifiers so I assume it must have something to do with the larger integral structures like Long. Has anyone else noticed this? Thanks
asked Jan 13, 2015 at 10:20
WraithWireless
6849 silver badges22 bronze badges
1 Answer 1
You should unpack with:
struct.unpack("!L",value)
Since data is sent over network you should unpack using network ordering - !
answered Jan 13, 2015 at 10:30
dmg
7,7363 gold badges26 silver badges33 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
struct.unpack("!L",value)orstruct.unpack(">L",value). Yields the correct result.!means network format. So I'm guessing that is what you need.