On Fri, Nov 19, 2004 at 07:53:19AM +0900, Joe Van Dyk wrote:
> I have a bunch of binary data consisting of 4 ints stored inside an unsigned
> long.
>
> Here's psuedo C code to extract out the ints:
>
> // data is a FILE pointer to the file
> unsigned long temp;
> fread(temp, sizeof(temp), 1, data);
> int first = temp >> 24;
> int second = temp << 8 >> 24;
> int third = temp << 16 >> 24;
> int fourth = temp << 24 >> 24;
>
>
> I'm trying to do the same thing in Ruby, but I'm having difficulties with
> the bitshifting. Any ideas? Would it make since to inline C code in Ruby
> for this?
str = someio.read 16
first, second, third, fourth = str.unpack("l4")
--
Hassle-free packages for Ruby?
RPA is available from
http://www.rubyarchive.org/