Hex to 4-byte/32-bit quantity

M

Mattias Bud

I'm parsing a binary file and it contains (reading the specs on the
format) uInt32Number, 4-byte/32-bit quantities.

On the specific positions I read the value 0x000a - how do I turn this
into a 32-bit quantity?

Cheers
Mattias
 
M

Mattias Bud

Instead of converting the bytes to hex first I just unpacked them:

s.unpack("N")
 
B

Brian Candler

I'm parsing a binary file and it contains (reading the specs on the
format) uInt32Number, 4-byte/32-bit quantities.

On the specific positions I read the value 0x000a - how do I turn this
into a 32-bit quantity?

0x00 0x0a is only 16 bits. Assuming you mean 0x00 0x00 0x00 0x0a:

irb(main):001:0> s = "\x00\x00\x00\x0a"
=> "\000\000\000\n"
irb(main):002:0> puts s.unpack("N")[0]
10
=> nil
 
M

Mattias Bud

0x00 0x0a is only 16 bits. Assuming you mean 0x00 0x00 0x00 0x0a:

Yes - this was what I ment.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top