Reading binary data into numeric types

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.

On Sat, Jun 20, 2015 at 9:29 PM, Barry DeZonia
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
Hopefully you don't have some requirement to reinvent this wheel; the binary package already provides it, including support for endianness. http://hackage.haskell.org/package/binary -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (2)
-
Barry DeZonia
-
Brandon Allbery