Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Module for converting between boolean values and strings containing '0's | and '1's
Synopsis
- boolToBin :: Bool -> Char
- boolsToBin :: [Bool] -> String
- binToBool :: Char -> Bool
- binToBools :: String -> [Bool]
- stringToBools :: String -> [Bool]
Documentation
boolToBin :: Bool -> Char Source #
Converts a Bool to a '1' or '0'
Examples
>>>
boolToBin True
'1'>>>
boolToBin False
'0'
boolsToBin :: [Bool] -> String Source #
Converts a list of Bools to a binary string
Examples
>>>
boolsToBin [True, False, True, True]
"1011"
binToBool :: Char -> Bool Source #
Converts a binary character to a Bool
Examples
>>>
binToBool '0'
False>>>
binToBool '1'
True>>>
binToBool '2'
*** Exception: Invalid binary character: '2' (valid binary characters are '0' and '1')
binToBools :: String -> [Bool] Source #
Converts a binary string to a list of Bools
Examples
>>>
binToBools "1011"
[True,False,True,True]>>>
binToBools "1012"
*** Exception: Invalid binary character: '2' (valid binary characters are '0' and '1')
stringToBools :: String -> [Bool] Source #
Converts a string containing '0's and '1's to a list of Bools, ignoring any characters that are not '0' or '1'
Examples
>>>
stringToBools "1011"
[True,False,True,True]>>>
stringToBools "1012"
[True,False,True]>>>
stringToBools "Hello, Haskell!"
[]>>>
stringToBools "On the 10th of March, 1901, Hacksell Kerry placed 21st\n\ \ in the 100m dash, with a time of 12.3 seconds, wearing the number 101"
[True,False,True,False,True,True,True,False,False,True,True,False,True]