Safe Haskell | None |
---|
Documentation
class (IvoryBits a, IvoryBits b) => BitSplit a b | a -> b whereSource
Extraction of the upper or lower half of a bit type into the next smallest bit type.
class (IvoryBits a, IvoryBits b) => BitCast a b whereSource
A narrowing cast from one bit type to another. This explicitly discards the upper bits of the input value to return a smaller type, and is only defined for unsigned integers.
extractByte :: BitCast a Uint8 => a -> (Uint8, a)Source
Extract the least significant byte from an integer. This returns the two values (x & 0xFF, x >> 8), with the first value safely casted to an 8-bit integer.
This is convenient to use with a state monad and sets, such as:
fst $ runState x $ do a <- sets extractByte b <- sets extractByte return (a, b)