On Feb 14, 2007, at 2:27 PM, Harris Reynolds wrote:

> Let's say I have 4 bytes:
>
> 255 255 255 236

 >> bytes = [255, 255, 255, 236].map { |b| b.chr }.join
=> "\377\377\377\354"

> The binary representation of this is:
>
> 11111111
> 11111111
> 11111111
> 11101100

 >> bytes.unpack("B*").first.scan(/[01]{8}/)
=> ["11111111", "11111111", "11111111", "11101100"]

> The decimal number should be -20.  Does anyone know how to convert  
> these 4 bytes into an Integer?

This is where I had trouble.  I found the following:

 >> bytes.reverse.unpack("l*").first
=> -20

This is tied to my processor though.  I had to reverse the bytes  
because they are not in the order my machine expects.

unpack() has directives for when the order is known, but all of those  
seemed to be unsigned.

I'm anxious to see the cross-platform solution for this...

James Edward Gray II