Skip to content

Instantly share code, notes, and snippets.

@SKoschnicke
Created May 30, 2010 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SKoschnicke/419208 to your computer and use it in GitHub Desktop.
Save SKoschnicke/419208 to your computer and use it in GitHub Desktop.
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