ASCII code thing...what gives?

T

Todd

Hello,

irb(main):001:0> ?T
=> 84

irb(main):002:0> "\84"
=> "84"

irb(main):003:0> "\124"
=> "T"

irb(main):004:0> "\124\84"
=> "T84"

What? Do these operators not do what I think they should?

Todd
 
B

Bill Kelly

Hi,

From: "Todd said:
irb(main):001:0> ?T
=> 84

irb(main):002:0> "\84"
=> "84"

irb(main):003:0> "\124"
=> "T"

irb(main):004:0> "\124\84"
=> "T84"

8 is too big for octal... :) So I think the \8 is just
ignored, leaving the literal "84".



Regards,

Bill
 
B

Bob Hutchison

That 124 octal equals 84 decimal may be a clue. I don't have my Ruby
docs here or I'd look further myself.
 
J

Jeffrey Dik

Hello,

irb(main):001:0> ?T
=> 84

irb(main):002:0> "\84"
=> "84"

irb(main):003:0> "\124"
=> "T"

irb(main):004:0> "\124\84"
=> "T84"

What? Do these operators not do what I think they should?

84 is 124 in octal.

Hope that helps,
Jeff
 
D

Dale Martenson

irb(main):001:0> ?T

The '?' operator returns the ascii code of the character
irb(main):002:0> "\84"
=> "84"

I think this is evaluated as "\8" and "4". "\x" returns "x" so "84"
makes sense.

Note: there is no decimal substitution only "\nnn" (octal) and "\xnn"
(hex).
irb(main):003:0> "\124"
=> "T"

This matches the octal form a substitution so it is correct.
irb(main):004:0> "\124\84"
=> "T84"

As previously shown the first part matches the octal substitution
"\124" => "T". The second part matches "\8" + "4" => "84". Thus "T84"
is correct.
 
T

Todd

Dale said:
The '?' operator returns the ascii code of the character


I think this is evaluated as "\8" and "4". "\x" returns "x" so "84"
makes sense.

Note: there is no decimal substitution only "\nnn" (octal) and "\xnn"
(hex).


This matches the octal form a substitution so it is correct.


As previously shown the first part matches the octal substitution
"\124" => "T". The second part matches "\8" + "4" => "84". Thus "T84"
is correct.

Yes, thanks to everyone for the quick response. I don't even know
where I originally heard of the "\nn" operator, so couldn't find the
doc on it (maybe Pickaxe?).

my_num.chr will work perfect.

Thanks again,
Todd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top