From: Wes Gamble Date: 2006-03-22T08:28:01+09:00 Subject: Re: Newbie: How do I get hex formatted bytes from a file? Answer: puts "Magic number is: #{magic_number.unpack('H*')}" Thanks for all the help. Argh! I sure wish there were a get_bytes() method on the File and/or IO objects. :) WG Wes Gamble wrote: > Why do I have to read my bytes into a string and then convert them back? > > Is there any way to read an array of bytes from my file? > > WG > > Daniel Harple wrote: >> On Mar 21, 2006, at 11:43 PM, Wes Gamble wrote: >> >>> Daniel, >>> >>> Not to be obtuse, but what is the # sign for in the specification? >>> >>> And what is the mod 100 -> 0x64 business about? >>> >>> wg >> >> Sorry, I misread your question. What you need is String#unpack. Do a >> 'ri String#upack'. String#% is the format method. It's function is >> the same as printf. See Kernel#sprintf for a list of format options >> (including #). >> >> -- Daniel -- Posted via http://www.ruby-forum.com/.