From: Harris Reynolds Date: 2006-06-10T07:22:07+09:00 Subject: Re: Converting a Float back to bytes --0-1831962756-1149891716=:63147 Content-Type: text/plain; charset=us-ascii Thanks Ryan... I had orignally thought this shouldn't be any harder than calling unpack coming from the oposite direction; nonetheless it didn't dawn on me to simply stuff the float into an array and call pack. Gotta love learning a new language! Thanks, ~harris ----- Original Message ---- From: Ryan Leavengood To: ruby-talk ML Sent: Friday, June 9, 2006 5:55:56 PM Subject: Re: Converting a Float back to bytes On 6/9/06, Harris Reynolds wrote: > This is good stuff. I am now getting the correct Float object (21.0) from a string of bytes > ("@5\000\000\000\000\000\000"). Now... here is a question... is there an easy way to go > from the Float back to bytes. This seems like it may be much more difficult. > > something like this... > > float_object = 21.0 > bytes = SOME_API_HERE.convert(float_object) Hi Harris, Keep in mind for things like this you always have the method pair Array#pack and String#unpack: C:\P4WS>irb irb(main):001:0> f = 21.0 => 21.0 irb(main):002:0> b = [f].pack("D") => "\000\000\000\000\000\0005@" irb(main):003:0> b.unpack("D") => [21.0] Ryan --0-1831962756-1149891716=:63147--