0

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
2
  • Is the value packed with python? Commented Jan 13, 2015 at 10:25
  • Also using struct.unpack("!L",value) or struct.unpack(">L",value). Yields the correct result. ! means network format. So I'm guessing that is what you need. Commented Jan 13, 2015 at 10:29

1 Answer 1

2

You should unpack with:

struct.unpack("!L",value)

Since data is sent over network you should unpack using network ordering - !

Source

answered Jan 13, 2015 at 10:30
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.