# Convert Binary to Float (and back)

**URL:** <https://www.ruby-forum.com/t/convert-binary-to-float-and-back/68871>\
**Category:** Ruby\
**Created:** [September 16, 2006, 2:55am UTC](https://www.ruby-forum.com/t/convert-binary-to-float-and-back/68871 "2006-09-16T02:55:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nebiru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nebiru](https://www.ruby-forum.com/u/Nebiru)\
**Post date:** [September 16, 2006, 2:55am UTC](https://www.ruby-forum.com/t/convert-binary-to-float-and-back/68871/1 "2006-09-16T02:55:41Z")

</div>

I’ve hacked together some rather ugly code to convert a Binary to a  
Float but was hoping there is a more elegant way using perhaps pack and  
unpack

---

<div class="post-metadata">

**Author:** ![Nebiru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nebiru](https://www.ruby-forum.com/u/Nebiru)\
**Post date:** [September 16, 2006, 3:57am UTC](https://www.ruby-forum.com/t/convert-binary-to-float-and-back/68871/2 "2006-09-16T03:57:43Z")

</div>

Nebiru wrote:

> I’ve hacked together some rather ugly code to convert a Binary to a  
> Float but was hoping there is a more elegant way using perhaps pack and  
> unpack

Look at

ri Array#pack

And play around with those options.

T.
