From: Roger Braun Date: 2011-04-21T11:53:11+09:00 Subject: Re: Binary file: SAT Hi, 2011/4/21 7stud -- : > 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