From: Morton Goldberg Date: 2007-02-15T08:02:07+09:00 Subject: Re: Converting Bytes to a Negative Integer On Feb 14, 2007, at 3:27 PM, Harris Reynolds wrote: > Let's say I have 4 bytes: > > 255 255 255 236 > > The binary representation of this is: > > 11111111 > 11111111 > 11111111 > 11101100 > > The decimal number should be -20. Does anyone know how to convert > these 4 bytes into an Integer? Maybe this will help: data = "" [255, 255, 255, 236].each { |e| data << e } data # => "\377\377\377\354" data.unpack('l').first # => -20 Regards, Morton