我想将十六进制转换为 bin haskell,这就是我所做的,但它似乎是错误的。有人可以帮忙吗?
bin:: Char -> String
bin'0' = "0000"
bin'1' = "0001"
bin'2' = "0010"
bin'3' = "0011"
bin'4' = "0100"
bin'5' = "0101"
bin'6' = "0110"
bin'7' = "0111"
bin'8' = "1000"
bin'9' = "1001"
bin'a' = "1010"
bin 'b' = "1011"
bin'c' = "1100"
bin'd' = "1101"
bin'e' = "1110"
bin'f' = "1111"
bin j = error "Your input is not a hex digit"
hex2bin :: Show a => Handle -> [a] -> IO ()
hex2bin fh [] = return ()
hex2bin fh (x:xs) = do
hPutStr fh (show(x) ++ "\n")
hex2bin fh xs