From: Ryan Leavengood Date: 2006-06-10T06:55:56+09:00 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