gray-code-0.3.1: Gray code encoder/decoder.

Safe HaskellSafe-Inferred
LanguageHaskell98

Codec.Binary.Gray.List

Description

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.

Synopsis

Documentation

gray :: [Bool] -> [Bool] Source

Take a list of bits (most significant last) in binary encoding and convert them to Gray code.

binary :: [Bool] -> [Bool] Source

Take a list of bits in Gray code and convert them to binary encoding (most significant bit last).

toList :: (Bits b, Num b) => b -> [Bool] Source

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' :: (FiniteBits b, Num b) => b -> [Bool] Source

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.

fromList :: (Bits b, Num b) => [Bool] -> b Source

Convert a list of bits in binary encoding to a number.

showBits :: [Bool] -> String Source

Render a list of bits as a string of 0s and 1s.