Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Gray code is a binary numeral system where two successive numbers differ in only one bit.
This module provides an interface to encode/decode
types.Bits
Algorithm: Haupt, R.L. and Haupt, S.E., Practical Genetic Algorithms, Second ed. (2004), 5.4. Gray Codes.
- gray :: (FiniteBits a, Num a) => a -> a
- binary :: (FiniteBits a, Num a) => a -> a
- showBits :: (FiniteBits a, Num a) => a -> String
Documentation
gray :: (FiniteBits a, Num a) => a -> a Source
Convert an integer number from binary to Gray code.
binary :: (FiniteBits a, Num a) => a -> a Source
Convert an integer number from Gray code to binary.
showBits :: (FiniteBits a, Num a) => a -> String Source
Render binary code as a string of 0
s and 1
s.
For example, (42::Int8)
is formatted as 101010
.