variety-0.1.0.2: integer arithmetic codes
Safe HaskellSafe-Inferred
LanguageHaskell2010

Codec.Arithmetic.Variety.BitVec

Synopsis

Documentation

data BitVec Source #

A vector of bits

Instances

Instances details
Monoid BitVec Source # 
Instance details

Defined in Codec.Arithmetic.Variety.BitVec

Semigroup BitVec Source # 
Instance details

Defined in Codec.Arithmetic.Variety.BitVec

Read BitVec Source # 
Instance details

Defined in Codec.Arithmetic.Variety.BitVec

Show BitVec Source # 
Instance details

Defined in Codec.Arithmetic.Variety.BitVec

Eq BitVec Source # 
Instance details

Defined in Codec.Arithmetic.Variety.BitVec

Methods

(==) :: BitVec -> BitVec -> Bool #

(/=) :: BitVec -> BitVec -> Bool #

Ord BitVec Source # 
Instance details

Defined in Codec.Arithmetic.Variety.BitVec

Construction

bitVec :: Int -> Integer -> BitVec Source #

Construct a BitVec from a length and Integer.

Conversion

fromBits :: [Bool] -> BitVec Source #

Construct from a list of bits. True is 1 and False is 0.

toBits :: BitVec -> [Bool] Source #

Return as a list of bits. True is 1 and False is 0.

fromBytes :: ByteString -> BitVec Source #

Construct from a lazy ByteString

toBytes :: BitVec -> ByteString Source #

Pack the bits into a lazy ByteString. Pads the left with 0s if the length is not a multiple of 8.

fromInteger :: Integer -> BitVec Source #

Read bits from the binary representation of an Integer. This excludes the possibility of any leading zeros. Use bitVec for more flexible construction.

toInteger :: BitVec -> Integer Source #

Return the Integer representation of the BitVec.

fromString :: String -> BitVec Source #

Read the code from a list of 0 and 1 chars.

toString :: BitVec -> String Source #

Return the bits as a list of 0 and 1 chars.

Methods

empty :: BitVec Source #

The empty bit vector.

null :: BitVec -> Bool Source #

Returns True iff the bit vector is empty.

length :: BitVec -> Int Source #

Returns the number of bits in the vector.

singleton :: Bool -> BitVec Source #

A vector of length 1 with the given bit.

append :: BitVec -> BitVec -> BitVec Source #

Concatenate two bit vectors.

take :: Int -> BitVec -> BitVec Source #

take n bv returns the bit vector consisting of the first n bits of bv.

drop :: Int -> BitVec -> BitVec Source #

drop n bv returns bv with the first n bits removed.

splitAt :: Int -> BitVec -> (BitVec, BitVec) Source #

splitAt n bv is equivalent to (take n bv, drop n bv)

replicate :: Int -> Bool -> BitVec Source #

replicate n b constructs a bit vector of length n with b the value of every bit.

countLeadingZeros :: BitVec -> Int Source #

Count the number of 0 bits preceeding the first 1 bit.

(!!) :: BitVec -> Int -> Bool infixl 9 Source #

Returns the value of a bit at a given index, with 0 being the index of the most significant (left-most) bit.

(!?) :: BitVec -> Int -> Maybe Bool infixl 9 Source #

Returns the value of a bit at a given index if within bounds, with 0 being the index of the most significant (left-most) bit.

Extra

bitLen :: Integer -> Int Source #

The number of bits in the binary expansion of a positive integer. For consistency with inductive definitions, leading zeros are not considered and so bitLen 0 == 0.