real-dice-0.1.0.2: Random number generation based on physical media touched by humans
Safe HaskellSafe-Inferred
LanguageGHC2021

RealDice.Convert.BinaryString

Description

Module for converting between boolean values and strings containing '0's | and '1's

Synopsis

Documentation

boolToBin :: Bool -> Char Source #

Converts a Bool to a '1' or '0'

Examples

Expand
>>> boolToBin True
'1'
>>> boolToBin False
'0'

boolsToBin :: [Bool] -> String Source #

Converts a list of Bools to a binary string

Examples

Expand
>>> boolsToBin [True, False, True, True]
"1011"

binToBool :: Char -> Bool Source #

Converts a binary character to a Bool

Examples

Expand
>>> 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

Expand
>>> 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

Expand
>>> 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]