[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Bitwise operations

Rob Lee

10/18/2006 11:29:00 PM

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-....

1 Answer

Joel VanderWerf

10/19/2006 2:54:00 AM

0

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/b...

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407