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

M Xyz functionallyharmonious at yahoo.com
Fri Dec 11 02:14:06 EST 2009


I've been trying to play around with binary data, but I haven't made much progress
trying to print the bits of a Double. With help from #haskell I've made it this far:

-- Printing the bits of an Int
main = do putStrLn $ showIntAtBase 2 (chr . (48+)) z ""

-- 103 = 1100111, after bit shifting 11001
z = shiftR (103 :: Int64) 2 

This is as far as I got with Doubles:

import Data.Binary.IEEE754
import qualified Data.ByteString.Lazy as BS
main = do BS.putStrLn $ runPut $ putFloat64be 4.123

Instead of playing with ByteStrings, is there just a way to fill an Int64 with the bits of a Double (Similar to Java's long = Double.doubleToLongBits(double))?



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


More information about the Beginners mailing list