| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.BinaryWord
Description
Extra operations on binary words of fixed length.
Synopsis
- class (FiniteBits w, FiniteBits (UnsignedWord w), FiniteBits (SignedWord w)) => BinaryWord w where
- type UnsignedWord w
- type SignedWord w
- unsignedWord :: w -> UnsignedWord w
- signedWord :: w -> SignedWord w
- unwrappedAdd :: w -> w -> (w, UnsignedWord w)
- unwrappedMul :: w -> w -> (w, UnsignedWord w)
- leadingZeroes :: w -> Int
- trailingZeroes :: w -> Int
- allZeroes :: w
- allOnes :: w
- msb :: w
- lsb :: w
- testMsb :: w -> Bool
- testLsb :: w -> Bool
- setMsb :: w -> w
- setLsb :: w -> w
- clearMsb :: w -> w
- clearLsb :: w -> w
- lMsb :: (Functor f, BinaryWord w) => (Bool -> f Bool) -> w -> f w
- lLsb :: (Functor f, BinaryWord w) => (Bool -> f Bool) -> w -> f w
Documentation
class (FiniteBits w, FiniteBits (UnsignedWord w), FiniteBits (SignedWord w)) => BinaryWord w where Source #
Two's complement, fixed length binary words.
Minimal complete definition
unsignedWord, signedWord, unwrappedAdd, unwrappedMul, leadingZeroes, trailingZeroes, allZeroes, allOnes, msb, testMsb, setMsb, clearMsb
Associated Types
type UnsignedWord w Source #
The unsigned variant type
type SignedWord w Source #
The signed variant type
Methods
unsignedWord :: w -> UnsignedWord w Source #
Convert the word to the unsigned type (identical to fromIntegral)
signedWord :: w -> SignedWord w Source #
Convert the word to the signed type (identical to fromIntegral)
unwrappedAdd :: w -> w -> (w, UnsignedWord w) Source #
Unwrapped addition
unwrappedMul :: w -> w -> (w, UnsignedWord w) Source #
Unwrapped multiplication
leadingZeroes :: w -> Int Source #
Number of leading (from MSB) zero bits
trailingZeroes :: w -> Int Source #
Number or trailing (from LSB) zero bits
The word with all bits set to 0
The word with all bits set to 1
The word with MSB set to 1 and all the other bits set to 0
The word with LSB set to 1 and all the other bits set to 0
Test if the MSB is 1
Test if the LSB is 1
Set the MSB to 1
Set the LSB to 1
Set the MSB to 0
Set the LSB to 0
Instances
| BinaryWord Int8 Source # | |
Defined in Data.BinaryWord Methods unsignedWord :: Int8 -> UnsignedWord Int8 Source # signedWord :: Int8 -> SignedWord Int8 Source # unwrappedAdd :: Int8 -> Int8 -> (Int8, UnsignedWord Int8) Source # unwrappedMul :: Int8 -> Int8 -> (Int8, UnsignedWord Int8) Source # leadingZeroes :: Int8 -> Int Source # trailingZeroes :: Int8 -> Int Source # testMsb :: Int8 -> Bool Source # testLsb :: Int8 -> Bool Source # setMsb :: Int8 -> Int8 Source # setLsb :: Int8 -> Int8 Source # | |
| BinaryWord Int16 Source # | |
Defined in Data.BinaryWord Methods unsignedWord :: Int16 -> UnsignedWord Int16 Source # signedWord :: Int16 -> SignedWord Int16 Source # unwrappedAdd :: Int16 -> Int16 -> (Int16, UnsignedWord Int16) Source # unwrappedMul :: Int16 -> Int16 -> (Int16, UnsignedWord Int16) Source # leadingZeroes :: Int16 -> Int Source # trailingZeroes :: Int16 -> Int Source # testMsb :: Int16 -> Bool Source # testLsb :: Int16 -> Bool Source # setMsb :: Int16 -> Int16 Source # setLsb :: Int16 -> Int16 Source # | |
| BinaryWord Int32 Source # | |
Defined in Data.BinaryWord Methods unsignedWord :: Int32 -> UnsignedWord Int32 Source # signedWord :: Int32 -> SignedWord Int32 Source # unwrappedAdd :: Int32 -> Int32 -> (Int32, UnsignedWord Int32) Source # unwrappedMul :: Int32 -> Int32 -> (Int32, UnsignedWord Int32) Source # leadingZeroes :: Int32 -> Int Source # trailingZeroes :: Int32 -> Int Source # testMsb :: Int32 -> Bool Source # testLsb :: Int32 -> Bool Source # setMsb :: Int32 -> Int32 Source # setLsb :: Int32 -> Int32 Source # | |
| BinaryWord Int64 Source # | |
Defined in Data.BinaryWord Methods unsignedWord :: Int64 -> UnsignedWord Int64 Source # signedWord :: Int64 -> SignedWord Int64 Source # unwrappedAdd :: Int64 -> Int64 -> (Int64, UnsignedWord Int64) Source # unwrappedMul :: Int64 -> Int64 -> (Int64, UnsignedWord Int64) Source # leadingZeroes :: Int64 -> Int Source # trailingZeroes :: Int64 -> Int Source # testMsb :: Int64 -> Bool Source # testLsb :: Int64 -> Bool Source # setMsb :: Int64 -> Int64 Source # setLsb :: Int64 -> Int64 Source # | |
| BinaryWord Word8 Source # | |
Defined in Data.BinaryWord Methods unsignedWord :: Word8 -> UnsignedWord Word8 Source # signedWord :: Word8 -> SignedWord Word8 Source # unwrappedAdd :: Word8 -> Word8 -> (Word8, UnsignedWord Word8) Source # unwrappedMul :: Word8 -> Word8 -> (Word8, UnsignedWord Word8) Source # leadingZeroes :: Word8 -> Int Source # trailingZeroes :: Word8 -> Int Source # testMsb :: Word8 -> Bool Source # testLsb :: Word8 -> Bool Source # setMsb :: Word8 -> Word8 Source # setLsb :: Word8 -> Word8 Source # | |
| BinaryWord Word16 Source # | |
Defined in Data.BinaryWord Methods unsignedWord :: Word16 -> UnsignedWord Word16 Source # signedWord :: Word16 -> SignedWord Word16 Source # unwrappedAdd :: Word16 -> Word16 -> (Word16, UnsignedWord Word16) Source # unwrappedMul :: Word16 -> Word16 -> (Word16, UnsignedWord Word16) Source # leadingZeroes :: Word16 -> Int Source # trailingZeroes :: Word16 -> Int Source # testMsb :: Word16 -> Bool Source # testLsb :: Word16 -> Bool Source # setMsb :: Word16 -> Word16 Source # setLsb :: Word16 -> Word16 Source # | |
| BinaryWord Word32 Source # | |
Defined in Data.BinaryWord Methods unsignedWord :: Word32 -> UnsignedWord Word32 Source # signedWord :: Word32 -> SignedWord Word32 Source # unwrappedAdd :: Word32 -> Word32 -> (Word32, UnsignedWord Word32) Source # unwrappedMul :: Word32 -> Word32 -> (Word32, UnsignedWord Word32) Source # leadingZeroes :: Word32 -> Int Source # trailingZeroes :: Word32 -> Int Source # testMsb :: Word32 -> Bool Source # testLsb :: Word32 -> Bool Source # setMsb :: Word32 -> Word32 Source # setLsb :: Word32 -> Word32 Source # | |
| BinaryWord Word64 Source # | |
Defined in Data.BinaryWord Methods unsignedWord :: Word64 -> UnsignedWord Word64 Source # signedWord :: Word64 -> SignedWord Word64 Source # unwrappedAdd :: Word64 -> Word64 -> (Word64, UnsignedWord Word64) Source # unwrappedMul :: Word64 -> Word64 -> (Word64, UnsignedWord Word64) Source # leadingZeroes :: Word64 -> Int Source # trailingZeroes :: Word64 -> Int Source # testMsb :: Word64 -> Bool Source # testLsb :: Word64 -> Bool Source # setMsb :: Word64 -> Word64 Source # setLsb :: Word64 -> Word64 Source # | |
lMsb :: (Functor f, BinaryWord w) => (Bool -> f Bool) -> w -> f w Source #
MSB lens.
lLsb :: (Functor f, BinaryWord w) => (Bool -> f Bool) -> w -> f w Source #
LSB lens.