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

Safe HaskellSafe-Inferred

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 -> aSource

Convert an integer number from binary to Gray code.

gray is undefined for negative numbers of types that do not have fixed bitsize, e.g. for negative Integers.

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

Convert an integer number from Gray code to binary.

binary is undefined for types that do not have fixed bitsize, e.g. for Integer.

showBits :: (Bits a, Num a) => a -> StringSource

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