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
···
--
Posted via http://www.ruby-forum.com/.
Instead of converting the bytes to hex first I just unpacked them:
s.unpack("N")
···
10
--
Posted via http://www.ruby-forum.com/\.
Mattias Bud wrote:
I'm parsing a binary file and it contains (reading the specs on the
format) uInt32Number, 4-byte/32-bit quantities.
You might find this library of mine useful:
http://raa.ruby-lang.org/project/bit-struct
···
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
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
···
On Sun, Feb 25, 2007 at 09:04:44PM +0900, Mattias Bud wrote:
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:
Yes - this was what I ment.
Thanks
···
--
Posted via http://www.ruby-forum.com/\.
You might find this library of mine useful:
http://raa.ruby-lang.org/project/bit-struct
Found that link in a previous post here also. I just wanted to get the
hang of it by doing it my self.
But thanks
Mattias
···
--
Posted via http://www.ruby-forum.com/\.