Data.Bits.Bitwise

bitwise-1.0.0.1: fast multi-dimensional unboxed bit packed Bool arrays

Copyright | (c) Claude Heiland-Allen 2012
License | BSD3
Maintainer | claude@mathr.co.uk
Stability | unstable
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Bits.Bitwise

Contents

- Boolean operations lifted to bitwise operations.
- Splitting/joining `Bits` to/from (lsb, msb).
- (Un)packing `Bits` to/from lists of `Bool`.
- (Un)packing `Word8` to/from 8-tuples of `Bool`.

Description

Lifting boolean operations on `Bool` to bitwise operations on `Bits`.

Packing bits into words, and unpacking words into bits.

Synopsis

- repeat :: Bits b => Bool -> b
- map :: Bits b => (Bool -> Bool) -> b -> b
- zipWith :: Bits b => (Bool -> Bool -> Bool) -> b -> b -> b
- or :: Bits b => b -> Bool
- and :: Bits b => b -> Bool
- any :: Bits b => (Bool -> Bool) -> b -> Bool
- all :: Bits b => (Bool -> Bool) -> b -> Bool
- isUniform :: Bits b => b -> Maybe Bool
- mask :: (Num b, Bits b) => Int -> b
- splitAt :: (Num b, Bits b) => Int -> b -> (b, b)
- joinAt :: Bits b => Int -> b -> b -> b
- fromBool :: Bits b => Bool -> b
- fromListLE :: Bits b => [Bool] -> b
- toListLE :: Bits b => b -> [Bool]
- fromListBE :: Bits b => [Bool] -> b
- toListBE :: FiniteBits b => b -> [Bool]
- packWord8LE :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Word8
- unpackWord8LE :: Word8 -> (Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool)
- packWord8BE :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Word8
- unpackWord8BE :: Word8 -> (Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool)

# Boolean operations lifted to bitwise operations.

repeat :: Bits b => Bool -> b #

Lift a boolean constant to a bitwise constant.

map #

Arguments

:: Bits b |
=> (Bool -> Bool) | operation
-> b |
-> b |

Lift a unary boolean operation to a bitwise operation.

The implementation is by exhaustive input/output case analysis: thus the operation provided must be total.

zipWith #

Arguments

:: Bits b |
=> (Bool -> Bool -> Bool) | operation
-> b |
-> b |
-> b |

Lift a binary boolean operation to a bitwise operation.

The implementation is by exhaustive input/output case analysis: thus the operation provided must be total.

or :: Bits b => b -> Bool #

True when any bit is set.

and :: Bits b => b -> Bool #

True when all bits are set.

any #

Arguments

:: Bits b |
=> (Bool -> Bool) | predicate
-> b |
-> Bool |

True when the predicate is true for any bit.

all #

Arguments

:: Bits b |
=> (Bool -> Bool) | predicate
-> b |
-> Bool |

True when the predicate is true for all bits.

isUniform :: Bits b => b -> Maybe Bool #

Determine if a `Bits` is all 1s, all 0s, or neither.

# Splitting/joining `Bits` to/from (lsb, msb).

mask #

Arguments

:: (Num b, Bits b) |
=> Int | count
-> b |

A mask with count least significant bits set.

splitAt #

Arguments

:: (Num b, Bits b) |
=> Int | split point
-> b | word
-> (b, b) | (lsb, msb)

Split a word into (lsb, msb). Ensures lsb has no set bits above the split point.

joinAt #

Arguments

:: Bits b |
=> Int | join point
-> b | least significant bits
-> b | most significant bits
-> b | word

Join lsb with msb to make a word. Assumes lsb has no set bits above the join point.

fromBool :: Bits b => Bool -> b #

The least significant bit.

# (Un)packing `Bits` to/from lists of `Bool`.

fromListLE #

Arguments

:: Bits b |
=> [Bool] | \[least significant bit, ..., most significant bit\]
-> b |

Convert a little-endian list of bits to `Bits`.

toListLE #

Arguments

:: Bits b |
=> b |
-> [Bool] | \[least significant bit, ..., most significant bit\]

Convert a `Bits` to a list of bits, in little-endian order.

fromListBE #

Arguments

:: Bits b |
=> [Bool] | \[most significant bit, ..., least significant bit\]
-> b |

Convert a big-endian list of bits to `Bits`.

toListBE #

Arguments

:: FiniteBits b |
=> b |
-> [Bool] | \[most significant bit, ..., least significant bit\]

Convert a `FiniteBits` to a list of bits, in big-endian order.

# (Un)packing `Word8` to/from 8-tuples of `Bool`.

packWord8LE #

Arguments

:: Bool | least significant bit
-> Bool |
-> Bool |
-> Bool |
-> Bool |
-> Bool |
-> Bool |
-> Bool | most significant bit
-> Word8 |

Pack bits into a byte in little-endian order.

unpackWord8LE #

Arguments

:: Word8 |
-> (Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool) | (least significant bit, ..., most significant bit)

Extract the bits from a byte in little-endian order.

packWord8BE #

Arguments

:: Bool | most significant bit
-> Bool |
-> Bool |
-> Bool |
-> Bool |
-> Bool |
-> Bool |
-> Bool | least significant bit
-> Word8 |

Pack bits into a byte in big-endian order.

unpackWord8BE #

Arguments

:: Word8 |
-> (Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool) | (most significant bit, ..., least significant bit)

Extract the bits from a byte in big-endian order.