Data.BinaryWord

data-bword-0.1.0.1: Extra operations on binary words of fixed length

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
- 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 #

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 #

The unsigned variant type

type SignedWord w #

The signed variant type

Methods

unsignedWord :: w -> UnsignedWord w #

Convert the word to the unsigned type (identical to `fromIntegral`)

signedWord :: w -> SignedWord w #

Convert the word to the signed type (identical to `fromIntegral`)

unwrappedAdd :: w -> w -> (w, UnsignedWord w) #

Unwrapped addition

unwrappedMul :: w -> w -> (w, UnsignedWord w) #

Unwrapped multiplication

leadingZeroes :: w -> Int #

Number of leading (from MSB) zero bits

trailingZeroes :: w -> Int #

Number or trailing (from LSB) zero bits

allZeroes :: w #

The word with all bits set to 0

allOnes :: w #

The word with all bits set to 1

msb :: w #

The word with MSB set to 1 and all the other bits set to 0

lsb :: w #

The word with LSB set to 1 and all the other bits set to 0

testMsb :: w -> Bool #

Test if the MSB is 1

testLsb :: w -> Bool #

Test if the LSB is 1

setMsb :: w -> w #

Set the MSB to 1

setLsb :: w -> w #

Set the LSB to 1

clearMsb :: w -> w #

Set the MSB to 0

clearLsb :: w -> w #

Set the LSB to 0

Instances

BinaryWord Int8 # |
Associated Types type UnsignedWord Int8 :: * # type SignedWord Int8 :: * # Methods unsignedWord :: Int8 -> UnsignedWord Int8 # signedWord :: Int8 -> SignedWord Int8 # unwrappedAdd :: Int8 -> Int8 -> (Int8, UnsignedWord Int8) # unwrappedMul :: Int8 -> Int8 -> (Int8, UnsignedWord Int8) # leadingZeroes :: Int8 -> Int # trailingZeroes :: Int8 -> Int # allZeroes :: Int8 # allOnes :: Int8 # msb :: Int8 # lsb :: Int8 # testMsb :: Int8 -> Bool # testLsb :: Int8 -> Bool # setMsb :: Int8 -> Int8 # setLsb :: Int8 -> Int8 # clearMsb :: Int8 -> Int8 # clearLsb :: Int8 -> Int8 #
BinaryWord Int16 # |
Associated Types type UnsignedWord Int16 :: * # type SignedWord Int16 :: * # Methods unsignedWord :: Int16 -> UnsignedWord Int16 # signedWord :: Int16 -> SignedWord Int16 # unwrappedAdd :: Int16 -> Int16 -> (Int16, UnsignedWord Int16) # unwrappedMul :: Int16 -> Int16 -> (Int16, UnsignedWord Int16) # leadingZeroes :: Int16 -> Int # trailingZeroes :: Int16 -> Int # allZeroes :: Int16 # allOnes :: Int16 # msb :: Int16 # lsb :: Int16 # testMsb :: Int16 -> Bool # testLsb :: Int16 -> Bool # setMsb :: Int16 -> Int16 # setLsb :: Int16 -> Int16 # clearMsb :: Int16 -> Int16 # clearLsb :: Int16 -> Int16 #
BinaryWord Int32 # |
Associated Types type UnsignedWord Int32 :: * # type SignedWord Int32 :: * # Methods unsignedWord :: Int32 -> UnsignedWord Int32 # signedWord :: Int32 -> SignedWord Int32 # unwrappedAdd :: Int32 -> Int32 -> (Int32, UnsignedWord Int32) # unwrappedMul :: Int32 -> Int32 -> (Int32, UnsignedWord Int32) # leadingZeroes :: Int32 -> Int # trailingZeroes :: Int32 -> Int # allZeroes :: Int32 # allOnes :: Int32 # msb :: Int32 # lsb :: Int32 # testMsb :: Int32 -> Bool # testLsb :: Int32 -> Bool # setMsb :: Int32 -> Int32 # setLsb :: Int32 -> Int32 # clearMsb :: Int32 -> Int32 # clearLsb :: Int32 -> Int32 #
BinaryWord Int64 # |
Associated Types type UnsignedWord Int64 :: * # type SignedWord Int64 :: * # Methods unsignedWord :: Int64 -> UnsignedWord Int64 # signedWord :: Int64 -> SignedWord Int64 # unwrappedAdd :: Int64 -> Int64 -> (Int64, UnsignedWord Int64) # unwrappedMul :: Int64 -> Int64 -> (Int64, UnsignedWord Int64) # leadingZeroes :: Int64 -> Int # trailingZeroes :: Int64 -> Int # allZeroes :: Int64 # allOnes :: Int64 # msb :: Int64 # lsb :: Int64 # testMsb :: Int64 -> Bool # testLsb :: Int64 -> Bool # setMsb :: Int64 -> Int64 # setLsb :: Int64 -> Int64 # clearMsb :: Int64 -> Int64 # clearLsb :: Int64 -> Int64 #
BinaryWord Word8 # |
Associated Types type UnsignedWord Word8 :: * # type SignedWord Word8 :: * # Methods unsignedWord :: Word8 -> UnsignedWord Word8 # signedWord :: Word8 -> SignedWord Word8 # unwrappedAdd :: Word8 -> Word8 -> (Word8, UnsignedWord Word8) # unwrappedMul :: Word8 -> Word8 -> (Word8, UnsignedWord Word8) # leadingZeroes :: Word8 -> Int # trailingZeroes :: Word8 -> Int # allZeroes :: Word8 # allOnes :: Word8 # msb :: Word8 # lsb :: Word8 # testMsb :: Word8 -> Bool # testLsb :: Word8 -> Bool # setMsb :: Word8 -> Word8 # setLsb :: Word8 -> Word8 # clearMsb :: Word8 -> Word8 # clearLsb :: Word8 -> Word8 #
BinaryWord Word16 # |
Associated Types type UnsignedWord Word16 :: * # type SignedWord Word16 :: * # Methods unsignedWord :: Word16 -> UnsignedWord Word16 # signedWord :: Word16 -> SignedWord Word16 # unwrappedAdd :: Word16 -> Word16 -> (Word16, UnsignedWord Word16) # unwrappedMul :: Word16 -> Word16 -> (Word16, UnsignedWord Word16) # leadingZeroes :: Word16 -> Int # trailingZeroes :: Word16 -> Int # allZeroes :: Word16 # allOnes :: Word16 # msb :: Word16 # lsb :: Word16 # testMsb :: Word16 -> Bool # testLsb :: Word16 -> Bool # setMsb :: Word16 -> Word16 # setLsb :: Word16 -> Word16 # clearMsb :: Word16 -> Word16 # clearLsb :: Word16 -> Word16 #
BinaryWord Word32 # |
Associated Types type UnsignedWord Word32 :: * # type SignedWord Word32 :: * # Methods unsignedWord :: Word32 -> UnsignedWord Word32 # signedWord :: Word32 -> SignedWord Word32 # unwrappedAdd :: Word32 -> Word32 -> (Word32, UnsignedWord Word32) # unwrappedMul :: Word32 -> Word32 -> (Word32, UnsignedWord Word32) # leadingZeroes :: Word32 -> Int # trailingZeroes :: Word32 -> Int # allZeroes :: Word32 # allOnes :: Word32 # msb :: Word32 # lsb :: Word32 # testMsb :: Word32 -> Bool # testLsb :: Word32 -> Bool # setMsb :: Word32 -> Word32 # setLsb :: Word32 -> Word32 # clearMsb :: Word32 -> Word32 # clearLsb :: Word32 -> Word32 #
BinaryWord Word64 # |
Associated Types type UnsignedWord Word64 :: * # type SignedWord Word64 :: * # Methods unsignedWord :: Word64 -> UnsignedWord Word64 # signedWord :: Word64 -> SignedWord Word64 # unwrappedAdd :: Word64 -> Word64 -> (Word64, UnsignedWord Word64) # unwrappedMul :: Word64 -> Word64 -> (Word64, UnsignedWord Word64) # leadingZeroes :: Word64 -> Int # trailingZeroes :: Word64 -> Int # allZeroes :: Word64 # allOnes :: Word64 # msb :: Word64 # lsb :: Word64 # testMsb :: Word64 -> Bool # testLsb :: Word64 -> Bool # setMsb :: Word64 -> Word64 # setLsb :: Word64 -> Word64 # clearMsb :: Word64 -> Word64 # clearLsb :: Word64 -> Word64 #

lMsb :: (Functor f, BinaryWord w) => (Bool -> f Bool) -> w -> f w #

MSB lens.

lLsb :: (Functor f, BinaryWord w) => (Bool -> f Bool) -> w -> f w #

LSB lens.