From: Chris Hulan Date: 2008-05-13T23:15:26+09:00 Subject: Re: How to convert character to hexadecimal? On May 13, 9:57 am, Iņaki Baz Castillo wrote: > 2008/5/13, Rob Biedenharn : > > > " ".unpack('H*')[0] > > => "20" > > "\t".unpack('H*')[0] > > => "09" > > > Put an "x" or "0x" on the front if you wish: > > "x"+(" ".unpack('H*')[0]) > > Great ! > > -- > Iņaki Baz Castillo > I think ' '[0].to_s.hex will produce the value and be a bit easier to read. YMMV For example: x = " \tX" 0.upto(x.size-1){|i| puts "x%02x"%x[i].to_s.hex} There is a String.each_char, but it wouldn't work in the version of ruby i have access to... Cheers