From: Mark Volkmann Date: 2006-03-22T07:40:10+09:00 Subject: Re: Newbie: How do I get hex formatted bytes from a file? On 3/21/06, Wes Gamble wrote: > I want to do: > > File.open(path_to_file, "r") do |f| > magic_number = f.read(8) > $stderr.print "Magic number is: #{magic_number}\n" > end > > but I want to print the bytes as HEX values - how do I do that? You can do this with String.unpack. In the PickAxe 2 book, see table 27.14 "Directives for String#unpack". In my copy, it's on page 624.