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

Safe HaskellSafe-Inferred
LanguageHaskell98

Codec.Binary.Gray.Bits

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 Bits types.

Algorithm: Haupt, R.L. and Haupt, S.E., Practical Genetic Algorithms, Second ed. (2004), 5.4. Gray Codes.

Synopsis

Documentation

gray :: (Bits a, Num a) => a -> a Source

Convert an integer number from binary to Gray code.

Results on negative values of unbounded integral types (like Integer) may be wrong.

binary :: (Bits a, Num a) => a -> a Source

Convert an integer number from Gray code to binary.

Results on negative values of unbounded integral types (like Integer) may be wrong.

showBits :: (Bits a, Num a) => a -> String Source

Render binary code as a string of 0s and 1s. For example, (42::Int8) is formatted as 101010.