From: Paul Brannan Date: 2001-10-05T01:14:52+09:00 Subject: [ruby-talk:22092] Re: Help with Array#pack On Fri, 5 Oct 2001, Jason Voegele wrote: > command = [1, 0, 1|2, 0x1000, 99, 0] > > These six entries in the array should correspond to the six fields in > the message header above. So the above array should be converted to > the binary string: > > BYTE 1 | BYTE 2 | BYTES 3&4 | BYTES 5-8 | BYTES 9-12 | BYTES 13-16 > ------ | ------ | --------- | --------- | ---------- | ----------- > 1 | 0 | 3 | 4096 | 99 | 0 Try this: def pack(arr) arr.pack("CCnnnn") end def display(x) x.each_byte do |b| puts b end end x = pack([1, 0, 1|2, 0x1000, 99, 0]) display x The 'C' means unsigned char, and the 'n' means 16-bit short (in network-byte-order, which is very important). Paul