[Haskell-cafe] Binary IO of a list of ints

Jamie Love jamie.love at aviarc.com.au
Thu Jan 24 22:20:08 EST 2008


Thanks Jed,

That works (or at least it's taking ages to error :-) )


Jed Brown wrote:
> On 24 Jan 2008, jamie.love at aviarc.com.au wrote:
>
>   
>> Hi there
>>
>> I have a list of ints, with values between 0 and 255 and I need to print them
>> out in little endian form to a file.
>>
>> I've been using Data.Binary for single values, e.g.
>>
>> runPut $ do
>> put 'B'
>> put (0 :: Int32)
>>     
>
> This will be big endian by default.  If it needs to be little endian,
> use Data.Binary.Put.putWord32le and relatives.  With a list, you could
> do something like:
>
>   runPut $ mapM_ (putWord32le . fromIntegral) listOfInts
>
> I hope this helps.
>
> Jed
>   

-- 
Jamie Love
Senior Consultant
Aviarc Australia
Mobile: +61 400 548 048



------------------------------------------------------------ 

This message has been scanned for viruses and dangerous content 
by MailScanner and is believed to be clean.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080125/22cb8494/attachment.htm


More information about the Haskell-Cafe mailing list