On Tue, Aug 16, 2011 at 12:34 PM, I=F1aki Baz Castillo <ibc / aliax.net> wrot=
e:
> Hi, I need to create binary data from Ruby to send via network some
> structure like this:
>
> - field 1: =A01 bit
> - field 2: =A01 bit
> - field 3: =A01 bit
> - field 4: =A01 bit
> - field 5: =A04 bits
> - field 6: =A01 bit
> - field 7: =A07 bits
> - field 8: =A016 bits
> (and so on)
>
> Which is the proer way to generate such binary data from Ruby?

There are various ways.  Off the top of my head:

1. Use Array#pack with 'B' or 'b'.

2. Use an integer to construct the whole bit data and convert it via
"%032b" % i.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/