3

I need to convert big-endian, 8-bytes, uint64 into an integer.

I can only find Q in the documentation for 64-bit unsigned, native endian (uint64_t) and nothing for 64-bit big-endian uint64.

So I just want to make sure that Q is the right one to use since Q does not specify that it is for big-endian

What I'm using: uid = io.read(8).unpack("Q")[0]

Or should I break it down into 2 32-bit integers then convert to string then concatenate like ...

uid = (io.read(4).unpack("N")[0].to_s + io.read(4).unpack("N")[0].to_s).to_i

3
  • 1
    Please read "How to Ask" and the linked pages, and "minimal reproducible example". What did you try? Did the code break? If so, where's the code and explanation showing where it broke. Commented Mar 23, 2017 at 23:28
  • So you checked the documentation and tested with data of a known quantity to verify it worked out? Commented Mar 23, 2017 at 23:35
  • @theTinMan I added code examples. Q doesn't specify that it's for a big-endian so that is what concerns me. Should I use Q or should I break the number into 2 numbers then concatenate? Commented Mar 24, 2017 at 0:14

1 Answer 1

3

From the same documentation page you linked:

S> L> Q>  | Integer | same as the directives without ">" except
s> l> q>  |         | big endian
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.