BitStruct-28bit-Ruby Beginner

Discussion in 'Ruby' started by Jaikanth Krishnaswamy, Nov 22, 2010.

  1. Hi ,
    I am a beginner to Ruby. I am using the ruby 1.9.2p0 (2010-08-18
    revision 29036) [i686-linux] and bit-struct (0.13.6)
    I am trying to construct a 28 bit length data element in my class
    and am getting the following
    error./usr/local/ruby/lib/ruby/gems/1.9.1/gems/bit-struct-0.13.6/lib/bit-struct/unsigned-field.rb:244:in
    `add_accessors_to': unsupported:

    I read through some limitations in
    byte alignments of Ruby BitStruct.
    I am hoping somebody can direct me to an example of how I can achieve a
    28 bit field with BitStruct or some other technique..

    Please let me know if this is an incorrect post for this forum and
    redirect me.

    --
    Posted via http://www.ruby-forum.com/.
    Jaikanth Krishnaswamy, Nov 22, 2010
    #1
    1. Advertising

  2. Yes I did read the documentation and was trying to see if some
    workaround could be used for odd sized field.
    This is part of a protocol simulation that the field is 28 bit long.
    Unfortunately it cannot be broken down to more sensible chunks as you
    suggested.

    Tim Roberts wrote in post #963486:
    > Jaikanth Krishnaswamy <> wrote:
    >
    >>Hi ,
    >>I am a beginner to Ruby. I am using the ruby 1.9.2p0 (2010-08-18
    >>revision 29036) [i686-linux] and bit-struct (0.13.6)
    >>I am trying to construct a 28 bit length data element in my class

    >
    > And did you read the documentation that says BitStruct supports fields
    > of
    > size 1 to 16, or multiples of 8? 28 is not a supported size.
    >
    >>and am getting the following
    >>error./usr/local/ruby/lib/ruby/gems/1.9.1/gems/bit-struct-0.13.6/lib/bit-struct/unsigned-field.rb:244:in
    >>`add_accessors_to': unsupported:

    >
    > That says you're using ruby 1.9.1, not that it matters much. The error
    > is
    > telling you that 28 bits is not a valid size.
    >
    >>I am hoping somebody can direct me to an example of how I can achieve a
    >>28 bit field with BitStruct or some other technique..

    >
    > Perhaps you should describe what you are actually trying to do. Are you
    > trying to parse a file that contains fields of oddly-sized data? There
    > may
    > be easier ways.
    >
    > If nothing else, you can compose your field out of smaller sizes, like
    > one
    > fields of 24 bits and an adjacent field of 4 bits. It depends on what
    > your
    > actual task is.


    --
    Posted via http://www.ruby-forum.com/.
    Jaikanth Krishnaswamy, Nov 30, 2010
    #2
    1. Advertising

  3. On Tue, Nov 30, 2010 at 10:58 PM, Jaikanth Krishnaswamy
    <> wrote:
    > Yes I did read the documentation and was trying to see if some
    > workaround could be used for odd sized field.
    > This is part of a protocol simulation that the field is 28 bit long.
    > Unfortunately it cannot be broken down to more sensible chunks as you
    > suggested.


    What about padding the 28bit data to 32bit length, with preceding
    zeros, for example?

    --
    Phillip Gawlowski

    Though the folk I have met,
    (Ah, how soon!) they forget
    When I've moved on to some other place,
    There may be one or two,
    When I've played and passed through,
    Who'll remember my song or my face.
    Phillip Gawlowski, Nov 30, 2010
    #3
  4. "Jaikanth Krishnaswamy" <> schrieb im
    Newsbeitrag news:...
    > Hi ,
    > I am a beginner to Ruby. I am using the ruby 1.9.2p0 (2010-08-18
    > revision 29036) [i686-linux] and bit-struct (0.13.6)
    > I am trying to construct a 28 bit length data element in my class
    > and am getting the following
    > error./usr/local/ruby/lib/ruby/gems/1.9.1/gems/bit-struct-0.13.6/lib/bit-struct/unsigned-field.rb:244:in
    > `add_accessors_to': unsupported:


    Why not use binary string representation:
    irb(main):019:0> b = "1234".unpack('B*').first
    => "00110001001100100011001100110100"
    irb(main):020:0> [b[8..15]].pack 'B*'
    => "2"
    Michael Bruschkewitz, Dec 2, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    No Class at ALL!!! beginner/beginner question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    572
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Feb 3, 2005
  2. Rensjuh
    Replies:
    7
    Views:
    964
    Mabden
    Sep 2, 2004
  3. Joel VanderWerf

    [ANN] BitStruct

    Joel VanderWerf, Oct 10, 2005, in forum: Ruby
    Replies:
    3
    Views:
    227
    Joel VanderWerf
    Oct 18, 2005
  4. Chuck Remes

    BitStruct technique

    Chuck Remes, May 14, 2009, in forum: Ruby
    Replies:
    3
    Views:
    146
    Chuck Remes
    May 16, 2009
  5. william nelson

    Beginner's Beginner

    william nelson, Apr 11, 2011, in forum: Ruby
    Replies:
    7
    Views:
    213
    7stud --
    Apr 12, 2011
Loading...

Share This Page