[Haskell-beginners] Reading binary data into numeric types

Barry DeZonia bdezonia at gmail.com
Sun Jun 21 01:29:30 UTC 2015


Hello,

I need to write some code that will read binary data from a file into
various types defined in Data.Int, Data.Word, and the floating types. I am
looking to make functions with signatures like Handle->IO Word16 and
Handle->IO Int32 and Handle->IO Float and others similarly defined. One
complication I am running into is that the data is stored in big endian
byte order. So my functions need to be flexible with byte ordering (and I
need to determine the endian ordering of the current platform). Anyhow I'm
pretty much a newbie and don't know how to do this. For a float in an
imperitive language I might read 4 bytes, possibly reorder them based on
platform endian value, and interpret the bytes as a float via a ptr. Would
the process be similar in Haskell? Pointers appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150620/a3eb17f9/attachment-0001.html>


More information about the Beginners mailing list