-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Gray code encoder/decoder. -- @package gray-code @version 0.3.1 -- | Gray code is a binary numeral system where two successive numbers -- differ in only one bit. -- -- This module provides an interface to encode/decode numbers represented -- as lists of Bool. -- -- Algorithm: Haupt, R.L. and Haupt, S.E., Practical Genetic Algorithms, -- Second ed. (2004), 5.4. Gray Codes. module Codec.Binary.Gray.List -- | Take a list of bits (most significant last) in binary encoding and -- convert them to Gray code. gray :: [Bool] -> [Bool] -- | Take a list of bits in Gray code and convert them to binary encoding -- (most significant bit last). binary :: [Bool] -> [Bool] -- | Convert a number to a list of bits in usual binary encoding (most -- significant bit last). Truncates unset major bits. -- -- The function may be also applied to unbounded integral types (like -- Integer): it will return a list of bits for positive values, -- and an empty list for negative values or zero. toList :: (Bits b, Num b) => b -> [Bool] -- | Convert a number to a list of bits in usual binary encoding (most -- significant bit last). -- -- Like toList, but returns all unset major bits too. So the -- length of the output is always the same length as finiteBitSize -- i. toList' :: (FiniteBits b, Num b) => b -> [Bool] -- | Convert a list of bits in binary encoding to a number. fromList :: (Bits b, Num b) => [Bool] -> b -- | Render a list of bits as a string of 0s and 1s. showBits :: [Bool] -> String -- | Gray code is a binary numeral system where two successive numbers -- differ in only one bit. -- -- This module provides an interface to encode/decode -- Bits types. -- -- Algorithm: Haupt, R.L. and Haupt, S.E., Practical Genetic Algorithms, -- Second ed. (2004), 5.4. Gray Codes. module Codec.Binary.Gray.Bits -- | Convert an integer number from binary to Gray code. -- -- Results on negative values of unbounded integral types (like -- Integer) may be wrong. gray :: (Bits a, Num a) => a -> a -- | Convert an integer number from Gray code to binary. -- -- Results on negative values of unbounded integral types (like -- Integer) may be wrong. binary :: (Bits a, Num a) => a -> a -- | Render binary code as a string of 0s and 1s. For -- example, (42::Int8) is formatted as 101010. showBits :: (Bits a, Num a) => a -> String module Codec.Binary.Gray