Bitwise operations

Discussion in 'Ruby' started by Rob Lee, Oct 19, 2006.

  1. Rob Lee

    Rob Lee Guest

    Hi,

    I have a binary packet stored in a string. I also have a packet
    specification and I'd like to print the first byte as a hex value to
    check it corresponds to the expected value from the specification
    ('7F'). I can't understand how to access the first byte from a string
    (a series of 8 bit bytes I believe). There don't seem to be any
    bit-shift operators in Ruby for a string - could anybody advise how I go
    about this ?

    Thanks

    --
    Posted via http://www.ruby-forum.com/.
    Rob Lee, Oct 19, 2006
    #1
    1. Advertising

  2. Rob Lee wrote:
    > Hi,
    >
    > I have a binary packet stored in a string. I also have a packet
    > specification and I'd like to print the first byte as a hex value to
    > check it corresponds to the expected value from the specification
    > ('7F'). I can't understand how to access the first byte from a string
    > (a series of 8 bit bytes I believe). There don't seem to be any
    > bit-shift operators in Ruby for a string - could anybody advise how I go
    > about this ?


    It would be overkill for just getting the first byte, but you may find
    bit-struct helpful in defining and parsing binary strings.

    http://raa.ruby-lang.org/project/bit-struct/

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, Oct 19, 2006
    #2
    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?Sm9u?=

    BitWise Operations

    =?Utf-8?B?Sm9u?=, Jan 23, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,344
    =?Utf-8?B?Sm9u?=
    Jan 24, 2006
  2. E. Robert Tisdale

    Re: seeking bitwise operations solution

    E. Robert Tisdale, Aug 17, 2003, in forum: C Programming
    Replies:
    4
    Views:
    428
  3. Carl
    Replies:
    3
    Views:
    4,065
    John Machin
    Aug 19, 2005
  4. Chris
    Replies:
    6
    Views:
    2,340
    Daniel Pitts
    Jan 5, 2007
  5. Alan Holloway

    newbie seeks insight on bitwise operations..

    Alan Holloway, Jul 28, 2004, in forum: C Programming
    Replies:
    11
    Views:
    427
    Keith Thompson
    Jul 30, 2004
Loading...

Share This Page