Gray code is a binary numeral system where two successive numbers differ in only one bit.
- binaryToGray :: [Bool] -> [Bool]
- grayToBinary :: [Bool] -> [Bool]
- bitsToBinary :: Bits b => b -> [Bool]
- binaryToBits :: Bits a => [Bool] -> a
- showBinary :: [Bool] -> String
List functions (for [Bool]
)
binaryToGray :: [Bool] -> [Bool]Source
Takes a list of bits (most significant last) in binary encoding and converts them to Gray code.
Algorithm: Haupt, R.L. and Haupt, S.E., Practical Genetic Algorithms, Second ed. (2004), 5.4. Gray Codes.
grayToBinary :: [Bool] -> [Bool]Source
Takes a list of bits in Gray code and converts them to binary encoding (most significant bit last).
Algorithm: Haupt, R.L. and Haupt, S.E., Practical Genetic Algorithms, Second ed. (2004), 5.4. Gray Codes.
bitsToBinary :: Bits b => b -> [Bool]Source
Convert a number to a list of bits in usual binary encoding (most significant last).
As bitSize
, bitsToBinary
is undefined for types that do not
have fixed bitsize, like Integer
.
binaryToBits :: Bits a => [Bool] -> aSource
Convert a list of bits in binary encoding to a number.
showBinary :: [Bool] -> StringSource
Render a list of bits as a 0-1 string.