haskell-works / hw-bits

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bitShow seems backwards

chris-martin opened this issue · comments

λ> import Data.Word
λ> import Data.Int
λ> import HaskellWorks.Data.Bits.BitShow

λ> bitShow @Int8 1
"10000000"

λ> bitShow @Word8 1
"10000000"

I expected "00000001" for both. Wouldn't that be more normal?

Could at least use some documentation.

Everything is in little-endian because the library is meant to be used with succinct data structures and its customary for those to be little-endian. The bitShow function also supports arbitrarily long bit-streams for example a vector of words and for streaming from a file.

If you think of a file as a stream of bits, little-endian also makes more sense in that context. This is because with little-endian the value of each bit in the file is fixed according to its position. The first bit is always worth 1, the second bit is always worth 2, the third bit is always worth 4, etc. With big endian, the value of the bit depends not just on its position in the file, but also the size of the file.

How about this? #100