Safe Haskell | None |
---|---|
Language | Haskell2010 |
- bitOp :: forall a. IvoryExpr a => ExpOp -> a -> a -> a
- class (Num a, IvoryExpr a) => IvoryBits a where
- class (IvoryBits a, IvoryBits b) => BitSplit a b | a -> b where
- class (IvoryBits a, IvoryBits b) => BitCast a b where
- bitCast :: a -> b
- class (IvoryBits unsigned, IvoryEq unsigned, IvoryExpr signed, Num signed, IvoryIntegral unsigned, Bounded unsigned, Bounded signed, IvoryOrd signed) => TwosComplementCast unsigned signed | signed -> unsigned, unsigned -> signed where
- twosComplementCast :: unsigned -> signed
- twosComplementRep :: signed -> unsigned
- extractByte :: BitCast a Uint8 => a -> (Uint8, a)
Documentation
class (IvoryBits a, IvoryBits b) => BitSplit a b | a -> b where Source
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 where Source
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.
class (IvoryBits unsigned, IvoryEq unsigned, IvoryExpr signed, Num signed, IvoryIntegral unsigned, Bounded unsigned, Bounded signed, IvoryOrd signed) => TwosComplementCast unsigned signed | signed -> unsigned, unsigned -> signed where Source
Re-interpret the bits of an unsigned integer as though they were a signed number in two's complement representation.
Nothing
twosComplementCast :: unsigned -> signed Source
twosComplementRep :: signed -> unsigned Source
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)