From: Robert Klemme Date: 2004-09-23T21:44:39+09:00 Subject: Re: negative numbers and binary formats "Florian Gross" schrieb im Newsbeitrag news:2rfrmgF18j1b3U1@uni-berlin.de... > Robert Klemme wrote: > > > After a bit experimenting I came up with this: > >>>[-7].pack("i").unpack("h*").shift.reverse.gsub(/^f+(?=f)/, '') > > > > => "f9" > > > >>>[-7000000].pack("i").unpack("h*").shift.reverse.gsub(/^f+(?=f)/, '') > > > > => "f953040" > > > > Florian, what do you think? > > Very nice, thank you. I wasn't aware of the range limit at first. Only > thing I would change is using .first instead of .shift. (For clarity) :-)) I deliberately choose #shift in order to make the array a bit smaller and remove all unnecessary references to the string - kind of GC paranoid. :-) Regards robert