Since the format's introduction in 5.10, pack
says:
W An unsigned char value (can be greater than 255).
For example, the following are equivalent:
pack('W', 0x2660)
chr(0x2660)
"\x{2660}"
For all values of $i
, length(pack('W', $i))
is one.
What's the size of a character (string element) in Ruby? Are they 8 bits like C, or larger like Java (16) and Perl (32 or 64)?
If they are limited to 8 bits, there is no direct equivalent of that code in Ruby. You'll need to use an array instead of a string.
If Ruby's character are wide enough to contain the numbers in question (e.g. 290), then a look through the Ruby docs reveals the following:
i.chr