[Haskell-beginners] Printing the bits of an Int|Double
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 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...
More information about the Beginners