On p. 131-132 in “Programming Ruby 2d.”, it talks about writing binary
data to files, but there’s no explanation of the syntax:
str1 = “\001\002\003”
I looked in the index of the book, I poured over “The Ruby Language”
chapter, and I also couldn’t find any escape character that was “\0”.
Is that Ruby’s unicode syntax? How about a ding dang explanation Mr.
Thomas?
I looked in the index of the book, I poured over “The Ruby Language”
chapter, and I also couldn’t find any escape character that was “\0”.
Is that Ruby’s unicode syntax? How about a ding dang explanation Mr.
Thomas?
You should look in the 3rd part, chapter 22, under “The Basic Types”.
Table 22.2, page 306 (in my PDF edition).
It says :
Table 22.2. Substitutions in double-quoted strings
On p. 131-132 in “Programming Ruby 2d.”, it talks about writing binary
data to files, but there’s no explanation of the syntax:
str1 = “\001\002\003”
I looked in the index of the book, I poured over “The Ruby Language”
chapter, and I also couldn’t find any escape character that was “\0”.
Is that Ruby’s unicode syntax?
I looked in the index of the book, I poured over “The Ruby Language”
chapter, and I also couldn’t find any escape character that was “\0”.
Is that Ruby’s unicode syntax? How about a ding dang explanation Mr.
Thomas?
You should look in the 3rd part, chapter 22, under “The Basic Types”.
Table 22.2, page 306 (in my PDF edition).
Ah. I didn’t realize there was a second column on the right.
I can’t understand why it is desirable to introduce yet another base
that is rarely used outside of chmod and od (without options). We
learned decimals, we got used to binary and even hex, but why do we
need octals just for these control characters when there is no
benefit compared to the hex representation (note: both take 4 chars
to display)?
On Sep 12, 2007, at 8:48 AM, Matthias Wächter wrote:
I can’t understand why it is desirable to introduce yet another base
that is rarely used outside of chmod and od (without options). We
learned decimals, we got used to binary and even hex, but why do we
need octals just for these control characters when there is no
benefit compared to the hex representation (note: both take 4 chars
to display)?
This is pure history.
Well, I understand that in history it was a popular format for
various reasons. But Ruby is now, and now we have 8 bit chars (aka
Bytes) and use hex nearly exclusively for them. Why not so in
String#inspect?
Or is the reason similar to the question why Float#to_s uses 15
instead of 17 significant bits to display? Pure convention? A (core)
developer rolling a dice somewhen?
On Sep 12, 2007, at 8:48 AM, Matthias Wächter wrote:
| \e Escape (0x1b) \cx Control-x
Does anyone know a good reason for outputting 8 bit byte characters
Matthias
This is pure history. The use of octal notation predates hex by a
long time. In my “The C Programming Language” [1978], 0ddd and 0xddd
were both valid integer literals, but only octal \ddd was valid for
character constants.
In fact, there’s a table of internal sizes for data types on various
machines which includes the Honeywell 6000 having a 9-bit char type
and 36-bit types for short, int, long, and float and 72-bit doubles.
For that machine, octal representation of bit patterns makes perfect
sense.