haskus-system-0.6.0.0: Haskus system programming framework

Safe HaskellNone
LanguageHaskell2010

Haskus.Format.Binary.Bits

Contents

Description

Operations on bits

Synopsis

Basic

Bit reversal

class BitReversable w where Source #

Data whose bits can be reversed

Minimal complete definition

reverseBits

Methods

reverseBits :: w -> w Source #

reverseBitsGeneric :: (FiniteBits a, Integral a) => a -> a Source #

Reverse bits in a Word

reverseLeastBits :: (FiniteBits a, BitReversable a) => Word -> a -> a Source #

Reverse the n least important bits of the given value. The higher bits are set to 0.

Mask

makeMask :: FiniteBits a => Word -> a Source #

makeMask 3 = 00000111

maskLeastBits :: FiniteBits a => Word -> a -> a Source #

Keep only the n least-significant bits of the given value

String conversion

bitsToString :: FiniteBits a => a -> String Source #

Convert bits into a string composed of '0' and '1' chars

bitsFromString :: Bits a => String -> a Source #

Convert a string of '0' and '1' chars into a word

Shift

getBitRange :: (BitReversable b, FiniteBits b) => BitOrder -> Word -> Word -> b -> b Source #

Take n bits at offset o and put them in the least-significant bits of the result

Various

bitOffset :: Word -> Word Source #

Compute bit offset (equivalent to x mod 8 but faster)

byteOffset :: Word -> Word Source #

Compute byte offset (equivalent to x div 8 but faster)