-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Gray code encoder/decoder.
--   
--   Gray code is a binary numeral system where two successive numbers
--   differ in only one bit.
--   
--   This package allows to convert numbers to one of the possible Gray
--   codes and back. Two binary representations of a number are supported:
--   <tt>[Bool]</tt> and types of <tt>FiniteBits</tt> type class.
--   <tt>FiniteBits</tt> is the default implementation.
@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 <tt>Bool</tt>.
--   
--   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
--   <a>Integer</a>): 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 <a>toList</a>, but returns all unset major bits too. So the
--   length of the output is always the same length as <tt>finiteBitSize
--   i</tt>.
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 <tt>0</tt>s and <tt>1</tt>s.
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
--   <tt><a>Bits</a></tt> 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
--   <a>Integer</a>) 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
--   <a>Integer</a>) may be wrong.
binary :: (Bits a, Num a) => a -> a

-- | Render binary code as a string of <tt>0</tt>s and <tt>1</tt>s. For
--   example, <tt>(42::Int8)</tt> is formatted as <tt>101010</tt>.
showBits :: (Bits a, Num a) => a -> String

module Codec.Binary.Gray
