7stud – wrote:
- Where does that format come from, i.e. no leading 0?
- Why is the output in octal and not hex?
I looked up String#<< and it says it converts any Fixnum between 0-255
to a character.
- Using what character set?
Actually, what’s your problem with all that?
Your ints specified in hex are actually converted to bytes in the
string. That, interpreted as utf-8, may mean an Ã©.
The conventional syntax for specifying bytes by their integer value in
string literals, used in C, shells and a number of other environments
(including Ruby) is a backslash followed by octal digits. (The leading 0
is used for specifying integer literals in octal.)
String#inspect (which I guess p is using) adopts this syntax for
displaying non-ascii and/or non-printing bytes in the string.
I really don’t get your third question. There’s no character set
involved here, beyond how you intended your two bytes to be interpreted.
Those two bytes remain the same, regardless how they are displayed. They
may mean two characters in plain old 8-bit charsets, they may mean e.g.
one Ã© in utf-8, or they may mean what p displays for them.