From: Todd Benson Date: 2007-06-19T01:43:03+09:00 Subject: Re: healp reading / writing binary strings. On 6/18/07, Melissa Silas wrote: > Thanks that helps.. Couple more questions.. > > for this example: > s = "\t\001" > puts s[0] -> 9 > How does \t come out as 9? Is that the tab char which in turn is the > number 9 in ascii table? It's just the number 9, but yes you can look at it that way. irb(main):001:0> 9.chr => "\t" > > for this example: > s = "\001" > Ok so now I know this is octal, does the octal value I supply correspond > to the ascii table as well? irb(main):002:0> 1.chr => "\001" irb(main):003:0> 255.chr => "\377" irb(main):004:0> 256.chr RangeError: 256 out of char range from (irb):24:in 'chr' from (irb):24 from :0 (I like that last "from" line :) > for this example: > s = "\x01" > for hex, does the hex value I supply correspond to the ascii table as > well? irb(main):005:0> "\x61" => "a" irb(main):006:0> ?a => 97 Your bytes are unprintable and so ruby simply tells you the byte value. What you do with that value is up to you.