Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Codec.Arithmetic.Variety.BitVec
Synopsis
- data BitVec
- bitVec :: Int -> Integer -> BitVec
- fromBits :: [Bool] -> BitVec
- toBits :: BitVec -> [Bool]
- fromBytes :: ByteString -> BitVec
- toBytes :: BitVec -> ByteString
- fromInteger :: Integer -> BitVec
- toInteger :: BitVec -> Integer
- fromString :: String -> BitVec
- toString :: BitVec -> String
- empty :: BitVec
- null :: BitVec -> Bool
- length :: BitVec -> Int
- singleton :: Bool -> BitVec
- append :: BitVec -> BitVec -> BitVec
- take :: Int -> BitVec -> BitVec
- drop :: Int -> BitVec -> BitVec
- splitAt :: Int -> BitVec -> (BitVec, BitVec)
- replicate :: Int -> Bool -> BitVec
- countLeadingZeros :: BitVec -> Int
- (!!) :: BitVec -> Int -> Bool
- (!?) :: BitVec -> Int -> Maybe Bool
- bitLen :: Integer -> Int
Documentation
A vector of bits
Construction
Conversion
fromBytes :: ByteString -> BitVec Source #
Construct from a lazy ByteString
toBytes :: BitVec -> ByteString Source #
Pack the bits into a lazy ByteString
. Pads the left with 0
s 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.
fromString :: String -> BitVec Source #
Read the code from a list of 0
and 1
chars.
Methods
take :: Int -> BitVec -> BitVec Source #
returns the bit vector consisting of the first take
n bvn
bits of bv
.
replicate :: Int -> Bool -> BitVec Source #
constructs a bit vector of length replicate
n bn
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.