Hi,

2011/4/21 7stud -- <bbxx789_05ss / yahoo.com>:
> 7stud -- wrote in post #994163:
>>
>> Once you are familiar with what each byte in your file represents, you
>> can use String#unpack to tell ruby how many bytes each integer occupies,
>> and how to interpret the integer.
>
> But, I can't get a simple unpack() example to work, so what do I know:
>
> str = "\x00\x00\x00\x61" #97 in hex, taking up 4 bytes
>
> results = str.unpack("L")
> p results
>
> --output:--
> [1627389952]

It's the correct result. L uses your systems endianness, which seems
to be little-endian. If you force big-endian by using N instead of L,
you will get your expected 97.

ruby-1.9.2-p180 :008 > str = "\x61\x00\x00\x00"
 => "a\u0000\u0000\u0000"
ruby-1.9.2-p180 :009 > results = str.unpack("L")
 => [97]

ruby-1.9.2-p180 :011 > str = "\x00\x00\x00\x61"
 => "\u0000\u0000\u0000a"
ruby-1.9.2-p180 :012 > results = str.unpack("N")
 => [97]


-- 
Roger Braun
rbraun.net | humoralpathologie.de