Created
May 30, 2010 18:16
-
-
Save SKoschnicke/419208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.IO | |
import Numeric(showIntAtBase) | |
import Char(ord, intToDigit) | |
main :: IO () | |
main = do | |
output stdin | |
printFile :: String -> IO () | |
printFile filename = | |
do file <- openFile filename ReadMode | |
output file | |
output :: Handle -> IO () | |
output inh = | |
do ineof <- hIsEOF inh | |
if ineof | |
then return () | |
else do inpChar <- hGetChar inh | |
putStr $ toBin inpChar | |
output inh | |
toBin :: Char -> String | |
toBin char = | |
padToEight $ showIntAtBase 2 intToDigit (ord char) "" | |
padToEight :: String -> String | |
padToEight string | length string >= 8 = string | |
padToEight string | otherwise = padToEight $ "0" ++ string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment