Commits

Sergey Astanin committed 8d0e2f2

toList' which returns lists of the same length as bitSize num. Minor version bump.

Comments (0)

Files changed (2)

Codec/Binary/Gray/List.hs

 --   Second ed. (2004),  5.4. Gray Codes.
 module Codec.Binary.Gray.List
     ( gray, binary
-    , toList, fromList
+    , toList, toList', fromList
     , showBits
     ) where
 
         go c bs@(b:_) = b `boolXOR` c : bs
 
 -- | Convert a number to a list of bits in usual binary encoding (most
--- significant last).
+-- significant bit last). Truncates unset major bits.
 -- 
 -- This function is undefined for negative numbers of types that do not
 -- have fixed bitsize, like 'Integer'.
       let rest = toList $ shiftR i 1  -- works only for positive i
       in  (testBit i 0 : rest)
 
+-- | 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 @bitSize i@.
+toList' :: (Bits b) => b -> [Bool]
+toList' i = map (testBit i) [0..bitSize i - 1]
+
 -- | Convert a list of bits in binary encoding to a number.
 fromList :: (Bits b) => [Bool] -> b
 fromList = sum . map fst . filter snd . zip (map (2^) [0..])
 -- The package version. See the Haskell package versioning policy
 -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
 -- standards guiding when and how versions should be incremented.
-Version:             0.2
+Version:             0.2.1
 
 -- A short (one-line) description of the package.
 Synopsis:            Gray code encoder/decoder.