Copyright | (c) 2011-2021 Amy de Buitléir |
---|---|
License | BSD-style |
Maintainer | amy@nualeargais.ie |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Gray encoding schemes. A Gray code is a list of values such that two successive values differ in only one digit. Usually the term /Gray code/ refers to the Binary Reflected Gray code (BRGC), but non-binary Gray codes have also been discovered. Some Gray codes are also cyclic: the last and first values differ in only one digit.
Synopsis
- grayCodes :: Int -> [[Bool]]
- integralToGray :: Bits a => a -> a
- grayToIntegral :: (Num a, Bits a) => a -> a
- naryGrayCodes :: [a] -> Int -> [[a]]
Documentation
grayCodes :: Int -> [[Bool]] Source #
generates the list of Binary Reflected Gray Code
(BRGC) numbers of length k. This code is cyclic.grayCodes
k
integralToGray :: Bits a => a -> a Source #
encodes integralToGray
nn
using a BRGC, and returns the
resulting bits as an integer. For example, encoding 17
in BRGC
results in 11001
, or 25. So integralToGray 17
returns 25
.
grayToIntegral :: (Num a, Bits a) => a -> a Source #
decodes grayToIntegral
nn
using a BRGC, and returns the
resulting integer. For example, 25 is 11001
, which is the code
for 17. So grayToIntegral 25
returns 17
.
naryGrayCodes :: [a] -> Int -> [[a]] Source #
generates a non-Boolean (or n-ary) Gray code
of length naryGrayCodes
xs kk
using the elements of xs
as "digits". This code
is cyclic.
Ex:
generates a ternary Gray code that
is four digits long.naryGrayCodes
"012" 4