[Haskell-beginners] Printing the bits of an Int|Double

M Xyz functionallyharmonious at yahoo.com
Fri Dec 11 21:46:22 EST 2009

Thanks Stephen for your response. 
With the help of #haskell I was actually able to find my answer:

import Char
import Numeric
import Data.Bits
import Data.Binary.Put
import Data.Binary.IEEE754
import qualified Data.ByteString.Lazy as LBS

main = do putStrLn . show $ map getBits (LBS.unpack . runPut $ putFloat64be 4.123)

getBits i = showIntAtBase 2 (chr . (48+)) i ""

--- On Fri, 12/11/09, Stephen Tetley <stephen.tetley at gmail.com> wrote:

From: Stephen Tetley <stephen.tetley at gmail.com>
Subject: Re: [Haskell-beginners] Printing the bits of an Int|Double
To: "M Xyz" <functionallyharmonious at yahoo.com>
Cc: beginners at haskell.org
Date: Friday, December 11, 2009, 9:29 AM


If you need double precision you might have to do it yourself.

In absence of comments in the code I posted, the algorithm I used for
single precision is from here:


Eventually I'll get around to double precision, but not soon.

Best wishes


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20091211/611c18ed/attachment.html

More information about the Beginners mailing list