
4 Jun
2007
4 Jun
'07
1:42 a.m.
The site seems to be asking for the internal floating point representation. So it doesn't matter if it's IEEE 754, if the ints are 2-complements, or whatever. I used this code as a quick hack for one of my programs, but I think it would work in this case. It should work for any Storable type. import qualified Data.ByteString as BS import Data.ByteString.Base import Foreign.ForeignPtr import Foreign.Storable binPut num = do fptr <- mallocForeignPtrBytes (sizeOf num) withForeignPtr (castForeignPtr fptr) (\x -> poke x num) BS.writeFile "/tmp/foo" (BS.reverse $ fromForeignPtr fptr (sizeOf num))