On Nov 6, 6:42 pm, Collin VanDyck <gluedtomys... / gmail.com> wrote: > Hello -- I'm trying to write out specific byte sequences over the > wire / to a file / etc. Let's say for example that I wanted to write > out > > 99 111 108 108 105 110 > > as a simple, six byte sequence to a file. In Java, I might use the > byte primitive, but it seems that in Ruby you have Fixnum and then a > Float for fractions. If I simply create a Fixnum using the 99 > literal, I think that that will create more than an 8-bit sequence > when I write out to the file. > > Any ideas on how to do this? I *think* you'll want to use Array#pack. E.g., to write them out in big-endian order: > a = [99, 111, 108, 108, 105, 110].pack 'n*' => "\000c\000o\000l\000l\000i\000n" > file.write a If you want little-endian, use 's*' (or 'S*' for unsigned) instead of 'n*'. See http://ruby-doc.org/core/ and check Array#pack for more details on the directives.