From: jason@... (Jason Voegele) Date: 2001-10-05T01:07:26+09:00 Subject: [ruby-talk:22091] Help with Array#pack I'm working with a network protocol that uses messages in the following format: BYTE 1 | BYTE 2 | BYTES 3&4 | BYTES 5-8 | BYTES 9-12 | BYTES 13-16 ------ | ------ | --------- | --------- | ---------- | ----------- cmd | var | flags | id | var | var Where "cmd" is a number 0-27, flags is a bitwise "or" of flag values, and "id" is a 4 byte identifier. "var" is a varying value of the appropriate size/range. I'd like to be able to specify an array that consists of 6 numbers, and pack them into the binary format specified above, for example: 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 (Or the 16 byte number 1329228233469478973560546180437377024 ;-) I've tried to use Array#pack to do this, but I can't figure out the proper format string for the pack method that makes this work, and the documentation is somewhat vague. Any pointers? Thanks, Jason Voegele