[Haskell-cafe] Re: Bytes to float
Simon Marlow
simonmarhaskell at gmail.com
Fri Jun 2 05:02:33 EDT 2006
Ivan Tikhonov wrote:
> Hello.
>
> I have 4 bytes long String and i want to convert it to Float.
> How can i do this in Haskell? Don't want to use Ptr's.
Try this:
> :m +Data.Array.IO Data.Word
> x <- newListArray (0,3) [0,0,40,66] :: IO (IOUArray Int Word8)
> y <- castIOUArray x :: IO (IOUArray Int Float)
> readArray y 0 >>= print
42.0
Cheers,
Simon
More information about the Haskell-Cafe
mailing list