planet-mitchell-0.1.0: Planet Mitchell

Bits

Contents

Synopsis

# Bits

class Eq a => Bits a where #

The Bits class defines bitwise operations over integral types.

• Bits are numbered from 0 with bit 0 being the least significant bit.

Minimal complete definition

Methods

(.&.) :: a -> a -> a infixl 7 #

Bitwise "and"

(.|.) :: a -> a -> a infixl 5 #

Bitwise "or"

xor :: a -> a -> a infixl 6 #

Bitwise "xor"

complement :: a -> a #

Reverse all the bits in the argument

shift :: a -> Int -> a infixl 8 #

shift x i shifts x left by i bits if i is positive, or right by -i bits otherwise. Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if the x is negative and with 0 otherwise.

An instance can define either this unified shift or shiftL and shiftR, depending on which is more convenient for the type in question.

rotate :: a -> Int -> a infixl 8 #

rotate x i rotates x left by i bits if i is positive, or right by -i bits otherwise.

For unbounded types like Integer, rotate is equivalent to shift.

An instance can define either this unified rotate or rotateL and rotateR, depending on which is more convenient for the type in question.

zeroBits :: a #

zeroBits is the value with all bits unset.

The following laws ought to hold (for all valid bit indices n):

• clearBit zeroBits n == zeroBits
• setBit   zeroBits n == bit n
• testBit  zeroBits n == False
• popCount zeroBits   == 0

This method uses clearBit (bit 0) 0 as its default implementation (which ought to be equivalent to zeroBits for types which possess a 0th bit).

Since: base-4.7.0.0

bit :: Int -> a #

bit i is a value with the ith bit set and all other bits clear.

Can be implemented using bitDefault if a is also an instance of Num.

See also zeroBits.

setBit :: a -> Int -> a #

x setBit i is the same as x .|. bit i

clearBit :: a -> Int -> a #

x clearBit i is the same as x .&. complement (bit i)

complementBit :: a -> Int -> a #

x complementBit i is the same as x xor bit i

testBit :: a -> Int -> Bool #

Return True if the nth bit of the argument is 1

Can be implemented using testBitDefault if a is also an instance of Num.

bitSizeMaybe :: a -> Maybe Int #

Return the number of bits in the type of the argument. The actual value of the argument is ignored. Returns Nothing for types that do not have a fixed bitsize, like Integer.

Since: base-4.7.0.0

bitSize :: a -> Int #

Return the number of bits in the type of the argument. The actual value of the argument is ignored. The function bitSize is undefined for types that do not have a fixed bitsize, like Integer.

isSigned :: a -> Bool #

Return True if the argument is a signed type. The actual value of the argument is ignored

shiftL :: a -> Int -> a infixl 8 #

Shift the argument left by the specified number of bits (which must be non-negative).

An instance can define either this and shiftR or the unified shift, depending on which is more convenient for the type in question.

unsafeShiftL :: a -> Int -> a #

Shift the argument left by the specified number of bits. The result is undefined for negative shift amounts and shift amounts greater or equal to the bitSize.

Defaults to shiftL unless defined explicitly by an instance.

Since: base-4.5.0.0

shiftR :: a -> Int -> a infixl 8 #

Shift the first argument right by the specified number of bits. The result is undefined for negative shift amounts and shift amounts greater or equal to the bitSize.

Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if the x is negative and with 0 otherwise.

An instance can define either this and shiftL or the unified shift, depending on which is more convenient for the type in question.

unsafeShiftR :: a -> Int -> a #

Shift the first argument right by the specified number of bits, which must be non-negative and smaller than the number of bits in the type.

Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if the x is negative and with 0 otherwise.

Defaults to shiftR unless defined explicitly by an instance.

Since: base-4.5.0.0

rotateL :: a -> Int -> a infixl 8 #

Rotate the argument left by the specified number of bits (which must be non-negative).

An instance can define either this and rotateR or the unified rotate, depending on which is more convenient for the type in question.

rotateR :: a -> Int -> a infixl 8 #

Rotate the argument right by the specified number of bits (which must be non-negative).

An instance can define either this and rotateL or the unified rotate, depending on which is more convenient for the type in question.

popCount :: a -> Int #

Return the number of set bits in the argument. This number is known as the population count or the Hamming weight.

Can be implemented using popCountDefault if a is also an instance of Num.

Since: base-4.5.0.0

Instances
 Interpret Bool as 1-bit bit-fieldSince: base-4.7.0.0 Instance detailsDefined in Data.Bits Methods(.&.) :: Bool -> Bool -> Bool #(.|.) :: Bool -> Bool -> Bool #xor :: Bool -> Bool -> Bool #shift :: Bool -> Int -> Bool #rotate :: Bool -> Int -> Bool #bit :: Int -> Bool #setBit :: Bool -> Int -> Bool #clearBit :: Bool -> Int -> Bool #testBit :: Bool -> Int -> Bool #bitSize :: Bool -> Int #shiftL :: Bool -> Int -> Bool #unsafeShiftL :: Bool -> Int -> Bool #shiftR :: Bool -> Int -> Bool #unsafeShiftR :: Bool -> Int -> Bool #rotateL :: Bool -> Int -> Bool #rotateR :: Bool -> Int -> Bool #popCount :: Bool -> Int # Since: base-2.1 Instance detailsDefined in Data.Bits Methods(.&.) :: Int -> Int -> Int #(.|.) :: Int -> Int -> Int #xor :: Int -> Int -> Int #shift :: Int -> Int -> Int #rotate :: Int -> Int -> Int #bit :: Int -> Int #setBit :: Int -> Int -> Int #clearBit :: Int -> Int -> Int #complementBit :: Int -> Int -> Int #testBit :: Int -> Int -> Bool #bitSize :: Int -> Int #isSigned :: Int -> Bool #shiftL :: Int -> Int -> Int #unsafeShiftL :: Int -> Int -> Int #shiftR :: Int -> Int -> Int #unsafeShiftR :: Int -> Int -> Int #rotateL :: Int -> Int -> Int #rotateR :: Int -> Int -> Int #popCount :: Int -> Int # Since: base-2.1 Instance detailsDefined in GHC.Int Methods(.&.) :: Int8 -> Int8 -> Int8 #(.|.) :: Int8 -> Int8 -> Int8 #xor :: Int8 -> Int8 -> Int8 #shift :: Int8 -> Int -> Int8 #rotate :: Int8 -> Int -> Int8 #bit :: Int -> Int8 #setBit :: Int8 -> Int -> Int8 #clearBit :: Int8 -> Int -> Int8 #testBit :: Int8 -> Int -> Bool #bitSize :: Int8 -> Int #shiftL :: Int8 -> Int -> Int8 #unsafeShiftL :: Int8 -> Int -> Int8 #shiftR :: Int8 -> Int -> Int8 #unsafeShiftR :: Int8 -> Int -> Int8 #rotateL :: Int8 -> Int -> Int8 #rotateR :: Int8 -> Int -> Int8 #popCount :: Int8 -> Int # Since: base-2.1 Instance detailsDefined in GHC.Int Methods(.&.) :: Int16 -> Int16 -> Int16 #(.|.) :: Int16 -> Int16 -> Int16 #xor :: Int16 -> Int16 -> Int16 #shift :: Int16 -> Int -> Int16 #rotate :: Int16 -> Int -> Int16 #bit :: Int -> Int16 #setBit :: Int16 -> Int -> Int16 #clearBit :: Int16 -> Int -> Int16 #testBit :: Int16 -> Int -> Bool #bitSize :: Int16 -> Int #shiftL :: Int16 -> Int -> Int16 #shiftR :: Int16 -> Int -> Int16 #rotateL :: Int16 -> Int -> Int16 #rotateR :: Int16 -> Int -> Int16 # Since: base-2.1 Instance detailsDefined in GHC.Int Methods(.&.) :: Int32 -> Int32 -> Int32 #(.|.) :: Int32 -> Int32 -> Int32 #xor :: Int32 -> Int32 -> Int32 #shift :: Int32 -> Int -> Int32 #rotate :: Int32 -> Int -> Int32 #bit :: Int -> Int32 #setBit :: Int32 -> Int -> Int32 #clearBit :: Int32 -> Int -> Int32 #testBit :: Int32 -> Int -> Bool #bitSize :: Int32 -> Int #shiftL :: Int32 -> Int -> Int32 #shiftR :: Int32 -> Int -> Int32 #rotateL :: Int32 -> Int -> Int32 #rotateR :: Int32 -> Int -> Int32 # Since: base-2.1 Instance detailsDefined in GHC.Int Methods(.&.) :: Int64 -> Int64 -> Int64 #(.|.) :: Int64 -> Int64 -> Int64 #xor :: Int64 -> Int64 -> Int64 #shift :: Int64 -> Int -> Int64 #rotate :: Int64 -> Int -> Int64 #bit :: Int -> Int64 #setBit :: Int64 -> Int -> Int64 #clearBit :: Int64 -> Int -> Int64 #testBit :: Int64 -> Int -> Bool #bitSize :: Int64 -> Int #shiftL :: Int64 -> Int -> Int64 #shiftR :: Int64 -> Int -> Int64 #rotateL :: Int64 -> Int -> Int64 #rotateR :: Int64 -> Int -> Int64 # Since: base-2.1 Instance detailsDefined in Data.Bits Methodsshift :: Integer -> Int -> Integer #rotate :: Integer -> Int -> Integer #bit :: Int -> Integer #setBit :: Integer -> Int -> Integer #testBit :: Integer -> Int -> Bool #shiftL :: Integer -> Int -> Integer #shiftR :: Integer -> Int -> Integer # Since: base-4.8.0.0 Instance detailsDefined in GHC.Natural Methodsshift :: Natural -> Int -> Natural #rotate :: Natural -> Int -> Natural #bit :: Int -> Natural #setBit :: Natural -> Int -> Natural #testBit :: Natural -> Int -> Bool #shiftL :: Natural -> Int -> Natural #shiftR :: Natural -> Int -> Natural # Since: base-2.1 Instance detailsDefined in Data.Bits Methods(.&.) :: Word -> Word -> Word #(.|.) :: Word -> Word -> Word #xor :: Word -> Word -> Word #shift :: Word -> Int -> Word #rotate :: Word -> Int -> Word #bit :: Int -> Word #setBit :: Word -> Int -> Word #clearBit :: Word -> Int -> Word #testBit :: Word -> Int -> Bool #bitSize :: Word -> Int #shiftL :: Word -> Int -> Word #unsafeShiftL :: Word -> Int -> Word #shiftR :: Word -> Int -> Word #unsafeShiftR :: Word -> Int -> Word #rotateL :: Word -> Int -> Word #rotateR :: Word -> Int -> Word #popCount :: Word -> Int # Since: base-2.1 Instance detailsDefined in GHC.Word Methods(.&.) :: Word8 -> Word8 -> Word8 #(.|.) :: Word8 -> Word8 -> Word8 #xor :: Word8 -> Word8 -> Word8 #shift :: Word8 -> Int -> Word8 #rotate :: Word8 -> Int -> Word8 #bit :: Int -> Word8 #setBit :: Word8 -> Int -> Word8 #clearBit :: Word8 -> Int -> Word8 #testBit :: Word8 -> Int -> Bool #bitSize :: Word8 -> Int #shiftL :: Word8 -> Int -> Word8 #shiftR :: Word8 -> Int -> Word8 #rotateL :: Word8 -> Int -> Word8 #rotateR :: Word8 -> Int -> Word8 # Since: base-2.1 Instance detailsDefined in GHC.Word Methods(.&.) :: Word16 -> Word16 -> Word16 #(.|.) :: Word16 -> Word16 -> Word16 #xor :: Word16 -> Word16 -> Word16 #shift :: Word16 -> Int -> Word16 #rotate :: Word16 -> Int -> Word16 #bit :: Int -> Word16 #setBit :: Word16 -> Int -> Word16 #clearBit :: Word16 -> Int -> Word16 #testBit :: Word16 -> Int -> Bool #shiftL :: Word16 -> Int -> Word16 #shiftR :: Word16 -> Int -> Word16 #rotateL :: Word16 -> Int -> Word16 #rotateR :: Word16 -> Int -> Word16 # Since: base-2.1 Instance detailsDefined in GHC.Word Methods(.&.) :: Word32 -> Word32 -> Word32 #(.|.) :: Word32 -> Word32 -> Word32 #xor :: Word32 -> Word32 -> Word32 #shift :: Word32 -> Int -> Word32 #rotate :: Word32 -> Int -> Word32 #bit :: Int -> Word32 #setBit :: Word32 -> Int -> Word32 #clearBit :: Word32 -> Int -> Word32 #testBit :: Word32 -> Int -> Bool #shiftL :: Word32 -> Int -> Word32 #shiftR :: Word32 -> Int -> Word32 #rotateL :: Word32 -> Int -> Word32 #rotateR :: Word32 -> Int -> Word32 # Since: base-2.1 Instance detailsDefined in GHC.Word Methods(.&.) :: Word64 -> Word64 -> Word64 #(.|.) :: Word64 -> Word64 -> Word64 #xor :: Word64 -> Word64 -> Word64 #shift :: Word64 -> Int -> Word64 #rotate :: Word64 -> Int -> Word64 #bit :: Int -> Word64 #setBit :: Word64 -> Int -> Word64 #clearBit :: Word64 -> Int -> Word64 #testBit :: Word64 -> Int -> Bool #shiftL :: Word64 -> Int -> Word64 #shiftR :: Word64 -> Int -> Word64 #rotateL :: Word64 -> Int -> Word64 #rotateR :: Word64 -> Int -> Word64 # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CDev -> CDev -> CDev #(.|.) :: CDev -> CDev -> CDev #xor :: CDev -> CDev -> CDev #shift :: CDev -> Int -> CDev #rotate :: CDev -> Int -> CDev #bit :: Int -> CDev #setBit :: CDev -> Int -> CDev #clearBit :: CDev -> Int -> CDev #testBit :: CDev -> Int -> Bool #bitSize :: CDev -> Int #shiftL :: CDev -> Int -> CDev #unsafeShiftL :: CDev -> Int -> CDev #shiftR :: CDev -> Int -> CDev #unsafeShiftR :: CDev -> Int -> CDev #rotateL :: CDev -> Int -> CDev #rotateR :: CDev -> Int -> CDev #popCount :: CDev -> Int # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CIno -> CIno -> CIno #(.|.) :: CIno -> CIno -> CIno #xor :: CIno -> CIno -> CIno #shift :: CIno -> Int -> CIno #rotate :: CIno -> Int -> CIno #bit :: Int -> CIno #setBit :: CIno -> Int -> CIno #clearBit :: CIno -> Int -> CIno #testBit :: CIno -> Int -> Bool #bitSize :: CIno -> Int #shiftL :: CIno -> Int -> CIno #unsafeShiftL :: CIno -> Int -> CIno #shiftR :: CIno -> Int -> CIno #unsafeShiftR :: CIno -> Int -> CIno #rotateL :: CIno -> Int -> CIno #rotateR :: CIno -> Int -> CIno #popCount :: CIno -> Int # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CMode -> CMode -> CMode #(.|.) :: CMode -> CMode -> CMode #xor :: CMode -> CMode -> CMode #shift :: CMode -> Int -> CMode #rotate :: CMode -> Int -> CMode #bit :: Int -> CMode #setBit :: CMode -> Int -> CMode #clearBit :: CMode -> Int -> CMode #testBit :: CMode -> Int -> Bool #bitSize :: CMode -> Int #shiftL :: CMode -> Int -> CMode #shiftR :: CMode -> Int -> CMode #rotateL :: CMode -> Int -> CMode #rotateR :: CMode -> Int -> CMode # Instance detailsDefined in System.Posix.Types Methods(.&.) :: COff -> COff -> COff #(.|.) :: COff -> COff -> COff #xor :: COff -> COff -> COff #shift :: COff -> Int -> COff #rotate :: COff -> Int -> COff #bit :: Int -> COff #setBit :: COff -> Int -> COff #clearBit :: COff -> Int -> COff #testBit :: COff -> Int -> Bool #bitSize :: COff -> Int #shiftL :: COff -> Int -> COff #unsafeShiftL :: COff -> Int -> COff #shiftR :: COff -> Int -> COff #unsafeShiftR :: COff -> Int -> COff #rotateL :: COff -> Int -> COff #rotateR :: COff -> Int -> COff #popCount :: COff -> Int # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CPid -> CPid -> CPid #(.|.) :: CPid -> CPid -> CPid #xor :: CPid -> CPid -> CPid #shift :: CPid -> Int -> CPid #rotate :: CPid -> Int -> CPid #bit :: Int -> CPid #setBit :: CPid -> Int -> CPid #clearBit :: CPid -> Int -> CPid #testBit :: CPid -> Int -> Bool #bitSize :: CPid -> Int #shiftL :: CPid -> Int -> CPid #unsafeShiftL :: CPid -> Int -> CPid #shiftR :: CPid -> Int -> CPid #unsafeShiftR :: CPid -> Int -> CPid #rotateL :: CPid -> Int -> CPid #rotateR :: CPid -> Int -> CPid #popCount :: CPid -> Int # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CSsize -> CSsize -> CSsize #(.|.) :: CSsize -> CSsize -> CSsize #xor :: CSsize -> CSsize -> CSsize #shift :: CSsize -> Int -> CSsize #rotate :: CSsize -> Int -> CSsize #bit :: Int -> CSsize #setBit :: CSsize -> Int -> CSsize #clearBit :: CSsize -> Int -> CSsize #testBit :: CSsize -> Int -> Bool #shiftL :: CSsize -> Int -> CSsize #shiftR :: CSsize -> Int -> CSsize #rotateL :: CSsize -> Int -> CSsize #rotateR :: CSsize -> Int -> CSsize # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CGid -> CGid -> CGid #(.|.) :: CGid -> CGid -> CGid #xor :: CGid -> CGid -> CGid #shift :: CGid -> Int -> CGid #rotate :: CGid -> Int -> CGid #bit :: Int -> CGid #setBit :: CGid -> Int -> CGid #clearBit :: CGid -> Int -> CGid #testBit :: CGid -> Int -> Bool #bitSize :: CGid -> Int #shiftL :: CGid -> Int -> CGid #unsafeShiftL :: CGid -> Int -> CGid #shiftR :: CGid -> Int -> CGid #unsafeShiftR :: CGid -> Int -> CGid #rotateL :: CGid -> Int -> CGid #rotateR :: CGid -> Int -> CGid #popCount :: CGid -> Int # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CNlink -> CNlink -> CNlink #(.|.) :: CNlink -> CNlink -> CNlink #xor :: CNlink -> CNlink -> CNlink #shift :: CNlink -> Int -> CNlink #rotate :: CNlink -> Int -> CNlink #bit :: Int -> CNlink #setBit :: CNlink -> Int -> CNlink #clearBit :: CNlink -> Int -> CNlink #testBit :: CNlink -> Int -> Bool #shiftL :: CNlink -> Int -> CNlink #shiftR :: CNlink -> Int -> CNlink #rotateL :: CNlink -> Int -> CNlink #rotateR :: CNlink -> Int -> CNlink # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CUid -> CUid -> CUid #(.|.) :: CUid -> CUid -> CUid #xor :: CUid -> CUid -> CUid #shift :: CUid -> Int -> CUid #rotate :: CUid -> Int -> CUid #bit :: Int -> CUid #setBit :: CUid -> Int -> CUid #clearBit :: CUid -> Int -> CUid #testBit :: CUid -> Int -> Bool #bitSize :: CUid -> Int #shiftL :: CUid -> Int -> CUid #unsafeShiftL :: CUid -> Int -> CUid #shiftR :: CUid -> Int -> CUid #unsafeShiftR :: CUid -> Int -> CUid #rotateL :: CUid -> Int -> CUid #rotateR :: CUid -> Int -> CUid #popCount :: CUid -> Int # Instance detailsDefined in System.Posix.Types Methodsshift :: CTcflag -> Int -> CTcflag #rotate :: CTcflag -> Int -> CTcflag #bit :: Int -> CTcflag #setBit :: CTcflag -> Int -> CTcflag #testBit :: CTcflag -> Int -> Bool #shiftL :: CTcflag -> Int -> CTcflag #shiftR :: CTcflag -> Int -> CTcflag # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CRLim -> CRLim -> CRLim #(.|.) :: CRLim -> CRLim -> CRLim #xor :: CRLim -> CRLim -> CRLim #shift :: CRLim -> Int -> CRLim #rotate :: CRLim -> Int -> CRLim #bit :: Int -> CRLim #setBit :: CRLim -> Int -> CRLim #clearBit :: CRLim -> Int -> CRLim #testBit :: CRLim -> Int -> Bool #bitSize :: CRLim -> Int #shiftL :: CRLim -> Int -> CRLim #shiftR :: CRLim -> Int -> CRLim #rotateL :: CRLim -> Int -> CRLim #rotateR :: CRLim -> Int -> CRLim # Instance detailsDefined in System.Posix.Types Methodsbit :: Int -> CBlkSize #testBit :: CBlkSize -> Int -> Bool # Instance detailsDefined in System.Posix.Types Methodsshift :: CBlkCnt -> Int -> CBlkCnt #rotate :: CBlkCnt -> Int -> CBlkCnt #bit :: Int -> CBlkCnt #setBit :: CBlkCnt -> Int -> CBlkCnt #testBit :: CBlkCnt -> Int -> Bool #shiftL :: CBlkCnt -> Int -> CBlkCnt #shiftR :: CBlkCnt -> Int -> CBlkCnt # Instance detailsDefined in System.Posix.Types Methodsbit :: Int -> CClockId #testBit :: CClockId -> Int -> Bool # Instance detailsDefined in System.Posix.Types Methodsbit :: Int -> CFsBlkCnt #testBit :: CFsBlkCnt -> Int -> Bool # Instance detailsDefined in System.Posix.Types Methodsbit :: Int -> CFsFilCnt #testBit :: CFsFilCnt -> Int -> Bool # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CId -> CId -> CId #(.|.) :: CId -> CId -> CId #xor :: CId -> CId -> CId #shift :: CId -> Int -> CId #rotate :: CId -> Int -> CId #bit :: Int -> CId #setBit :: CId -> Int -> CId #clearBit :: CId -> Int -> CId #complementBit :: CId -> Int -> CId #testBit :: CId -> Int -> Bool #bitSize :: CId -> Int #isSigned :: CId -> Bool #shiftL :: CId -> Int -> CId #unsafeShiftL :: CId -> Int -> CId #shiftR :: CId -> Int -> CId #unsafeShiftR :: CId -> Int -> CId #rotateL :: CId -> Int -> CId #rotateR :: CId -> Int -> CId #popCount :: CId -> Int # Instance detailsDefined in System.Posix.Types Methods(.&.) :: CKey -> CKey -> CKey #(.|.) :: CKey -> CKey -> CKey #xor :: CKey -> CKey -> CKey #shift :: CKey -> Int -> CKey #rotate :: CKey -> Int -> CKey #bit :: Int -> CKey #setBit :: CKey -> Int -> CKey #clearBit :: CKey -> Int -> CKey #testBit :: CKey -> Int -> Bool #bitSize :: CKey -> Int #shiftL :: CKey -> Int -> CKey #unsafeShiftL :: CKey -> Int -> CKey #shiftR :: CKey -> Int -> CKey #unsafeShiftR :: CKey -> Int -> CKey #rotateL :: CKey -> Int -> CKey #rotateR :: CKey -> Int -> CKey #popCount :: CKey -> Int # Instance detailsDefined in System.Posix.Types Methods(.&.) :: Fd -> Fd -> Fd #(.|.) :: Fd -> Fd -> Fd #xor :: Fd -> Fd -> Fd #complement :: Fd -> Fd #shift :: Fd -> Int -> Fd #rotate :: Fd -> Int -> Fd #bit :: Int -> Fd #setBit :: Fd -> Int -> Fd #clearBit :: Fd -> Int -> Fd #complementBit :: Fd -> Int -> Fd #testBit :: Fd -> Int -> Bool #bitSize :: Fd -> Int #isSigned :: Fd -> Bool #shiftL :: Fd -> Int -> Fd #unsafeShiftL :: Fd -> Int -> Fd #shiftR :: Fd -> Int -> Fd #unsafeShiftR :: Fd -> Int -> Fd #rotateL :: Fd -> Int -> Fd #rotateR :: Fd -> Int -> Fd #popCount :: Fd -> Int # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CChar -> CChar -> CChar #(.|.) :: CChar -> CChar -> CChar #xor :: CChar -> CChar -> CChar #shift :: CChar -> Int -> CChar #rotate :: CChar -> Int -> CChar #bit :: Int -> CChar #setBit :: CChar -> Int -> CChar #clearBit :: CChar -> Int -> CChar #testBit :: CChar -> Int -> Bool #bitSize :: CChar -> Int #shiftL :: CChar -> Int -> CChar #shiftR :: CChar -> Int -> CChar #rotateL :: CChar -> Int -> CChar #rotateR :: CChar -> Int -> CChar # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CSChar -> CSChar -> CSChar #(.|.) :: CSChar -> CSChar -> CSChar #xor :: CSChar -> CSChar -> CSChar #shift :: CSChar -> Int -> CSChar #rotate :: CSChar -> Int -> CSChar #bit :: Int -> CSChar #setBit :: CSChar -> Int -> CSChar #clearBit :: CSChar -> Int -> CSChar #testBit :: CSChar -> Int -> Bool #shiftL :: CSChar -> Int -> CSChar #shiftR :: CSChar -> Int -> CSChar #rotateL :: CSChar -> Int -> CSChar #rotateR :: CSChar -> Int -> CSChar # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CUChar -> CUChar -> CUChar #(.|.) :: CUChar -> CUChar -> CUChar #xor :: CUChar -> CUChar -> CUChar #shift :: CUChar -> Int -> CUChar #rotate :: CUChar -> Int -> CUChar #bit :: Int -> CUChar #setBit :: CUChar -> Int -> CUChar #clearBit :: CUChar -> Int -> CUChar #testBit :: CUChar -> Int -> Bool #shiftL :: CUChar -> Int -> CUChar #shiftR :: CUChar -> Int -> CUChar #rotateL :: CUChar -> Int -> CUChar #rotateR :: CUChar -> Int -> CUChar # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CShort -> CShort -> CShort #(.|.) :: CShort -> CShort -> CShort #xor :: CShort -> CShort -> CShort #shift :: CShort -> Int -> CShort #rotate :: CShort -> Int -> CShort #bit :: Int -> CShort #setBit :: CShort -> Int -> CShort #clearBit :: CShort -> Int -> CShort #testBit :: CShort -> Int -> Bool #shiftL :: CShort -> Int -> CShort #shiftR :: CShort -> Int -> CShort #rotateL :: CShort -> Int -> CShort #rotateR :: CShort -> Int -> CShort # Instance detailsDefined in Foreign.C.Types Methodsshift :: CUShort -> Int -> CUShort #rotate :: CUShort -> Int -> CUShort #bit :: Int -> CUShort #setBit :: CUShort -> Int -> CUShort #testBit :: CUShort -> Int -> Bool #shiftL :: CUShort -> Int -> CUShort #shiftR :: CUShort -> Int -> CUShort # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CInt -> CInt -> CInt #(.|.) :: CInt -> CInt -> CInt #xor :: CInt -> CInt -> CInt #shift :: CInt -> Int -> CInt #rotate :: CInt -> Int -> CInt #bit :: Int -> CInt #setBit :: CInt -> Int -> CInt #clearBit :: CInt -> Int -> CInt #testBit :: CInt -> Int -> Bool #bitSize :: CInt -> Int #shiftL :: CInt -> Int -> CInt #unsafeShiftL :: CInt -> Int -> CInt #shiftR :: CInt -> Int -> CInt #unsafeShiftR :: CInt -> Int -> CInt #rotateL :: CInt -> Int -> CInt #rotateR :: CInt -> Int -> CInt #popCount :: CInt -> Int # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CUInt -> CUInt -> CUInt #(.|.) :: CUInt -> CUInt -> CUInt #xor :: CUInt -> CUInt -> CUInt #shift :: CUInt -> Int -> CUInt #rotate :: CUInt -> Int -> CUInt #bit :: Int -> CUInt #setBit :: CUInt -> Int -> CUInt #clearBit :: CUInt -> Int -> CUInt #testBit :: CUInt -> Int -> Bool #bitSize :: CUInt -> Int #shiftL :: CUInt -> Int -> CUInt #shiftR :: CUInt -> Int -> CUInt #rotateL :: CUInt -> Int -> CUInt #rotateR :: CUInt -> Int -> CUInt # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CLong -> CLong -> CLong #(.|.) :: CLong -> CLong -> CLong #xor :: CLong -> CLong -> CLong #shift :: CLong -> Int -> CLong #rotate :: CLong -> Int -> CLong #bit :: Int -> CLong #setBit :: CLong -> Int -> CLong #clearBit :: CLong -> Int -> CLong #testBit :: CLong -> Int -> Bool #bitSize :: CLong -> Int #shiftL :: CLong -> Int -> CLong #shiftR :: CLong -> Int -> CLong #rotateL :: CLong -> Int -> CLong #rotateR :: CLong -> Int -> CLong # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CULong -> CULong -> CULong #(.|.) :: CULong -> CULong -> CULong #xor :: CULong -> CULong -> CULong #shift :: CULong -> Int -> CULong #rotate :: CULong -> Int -> CULong #bit :: Int -> CULong #setBit :: CULong -> Int -> CULong #clearBit :: CULong -> Int -> CULong #testBit :: CULong -> Int -> Bool #shiftL :: CULong -> Int -> CULong #shiftR :: CULong -> Int -> CULong #rotateL :: CULong -> Int -> CULong #rotateR :: CULong -> Int -> CULong # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CLLong -> CLLong -> CLLong #(.|.) :: CLLong -> CLLong -> CLLong #xor :: CLLong -> CLLong -> CLLong #shift :: CLLong -> Int -> CLLong #rotate :: CLLong -> Int -> CLLong #bit :: Int -> CLLong #setBit :: CLLong -> Int -> CLLong #clearBit :: CLLong -> Int -> CLLong #testBit :: CLLong -> Int -> Bool #shiftL :: CLLong -> Int -> CLLong #shiftR :: CLLong -> Int -> CLLong #rotateL :: CLLong -> Int -> CLLong #rotateR :: CLLong -> Int -> CLLong # Instance detailsDefined in Foreign.C.Types Methodsshift :: CULLong -> Int -> CULLong #rotate :: CULLong -> Int -> CULLong #bit :: Int -> CULLong #setBit :: CULLong -> Int -> CULLong #testBit :: CULLong -> Int -> Bool #shiftL :: CULLong -> Int -> CULLong #shiftR :: CULLong -> Int -> CULLong # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CBool -> CBool -> CBool #(.|.) :: CBool -> CBool -> CBool #xor :: CBool -> CBool -> CBool #shift :: CBool -> Int -> CBool #rotate :: CBool -> Int -> CBool #bit :: Int -> CBool #setBit :: CBool -> Int -> CBool #clearBit :: CBool -> Int -> CBool #testBit :: CBool -> Int -> Bool #bitSize :: CBool -> Int #shiftL :: CBool -> Int -> CBool #shiftR :: CBool -> Int -> CBool #rotateL :: CBool -> Int -> CBool #rotateR :: CBool -> Int -> CBool # Instance detailsDefined in Foreign.C.Types Methodsbit :: Int -> CPtrdiff #testBit :: CPtrdiff -> Int -> Bool # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CSize -> CSize -> CSize #(.|.) :: CSize -> CSize -> CSize #xor :: CSize -> CSize -> CSize #shift :: CSize -> Int -> CSize #rotate :: CSize -> Int -> CSize #bit :: Int -> CSize #setBit :: CSize -> Int -> CSize #clearBit :: CSize -> Int -> CSize #testBit :: CSize -> Int -> Bool #bitSize :: CSize -> Int #shiftL :: CSize -> Int -> CSize #shiftR :: CSize -> Int -> CSize #rotateL :: CSize -> Int -> CSize #rotateR :: CSize -> Int -> CSize # Instance detailsDefined in Foreign.C.Types Methods(.&.) :: CWchar -> CWchar -> CWchar #(.|.) :: CWchar -> CWchar -> CWchar #xor :: CWchar -> CWchar -> CWchar #shift :: CWchar -> Int -> CWchar #rotate :: CWchar -> Int -> CWchar #bit :: Int -> CWchar #setBit :: CWchar -> Int -> CWchar #clearBit :: CWchar -> Int -> CWchar #testBit :: CWchar -> Int -> Bool #shiftL :: CWchar -> Int -> CWchar #shiftR :: CWchar -> Int -> CWchar #rotateL :: CWchar -> Int -> CWchar #rotateR :: CWchar -> Int -> CWchar # Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methodsshift :: CIntPtr -> Int -> CIntPtr #rotate :: CIntPtr -> Int -> CIntPtr #bit :: Int -> CIntPtr #setBit :: CIntPtr -> Int -> CIntPtr #testBit :: CIntPtr -> Int -> Bool #shiftL :: CIntPtr -> Int -> CIntPtr #shiftR :: CIntPtr -> Int -> CIntPtr # Instance detailsDefined in Foreign.C.Types Methodsbit :: Int -> CUIntPtr #testBit :: CUIntPtr -> Int -> Bool # Instance detailsDefined in Foreign.C.Types Methodsshift :: CIntMax -> Int -> CIntMax #rotate :: CIntMax -> Int -> CIntMax #bit :: Int -> CIntMax #setBit :: CIntMax -> Int -> CIntMax #testBit :: CIntMax -> Int -> Bool #shiftL :: CIntMax -> Int -> CIntMax #shiftR :: CIntMax -> Int -> CIntMax # Instance detailsDefined in Foreign.C.Types Methodsbit :: Int -> CUIntMax #testBit :: CUIntMax -> Int -> Bool # Instance detailsDefined in Foreign.Ptr Methodsshift :: WordPtr -> Int -> WordPtr #rotate :: WordPtr -> Int -> WordPtr #bit :: Int -> WordPtr #setBit :: WordPtr -> Int -> WordPtr #testBit :: WordPtr -> Int -> Bool #shiftL :: WordPtr -> Int -> WordPtr #shiftR :: WordPtr -> Int -> WordPtr # Instance detailsDefined in Foreign.Ptr Methods(.&.) :: IntPtr -> IntPtr -> IntPtr #(.|.) :: IntPtr -> IntPtr -> IntPtr #xor :: IntPtr -> IntPtr -> IntPtr #shift :: IntPtr -> Int -> IntPtr #rotate :: IntPtr -> Int -> IntPtr #bit :: Int -> IntPtr #setBit :: IntPtr -> Int -> IntPtr #clearBit :: IntPtr -> Int -> IntPtr #testBit :: IntPtr -> Int -> Bool #shiftL :: IntPtr -> Int -> IntPtr #shiftR :: IntPtr -> Int -> IntPtr #rotateL :: IntPtr -> Int -> IntPtr #rotateR :: IntPtr -> Int -> IntPtr # () :=> (Bits Bool) Instance detailsDefined in Data.Constraint Methodsins :: () :- Bits Bool # () :=> (Bits Int) Instance detailsDefined in Data.Constraint Methodsins :: () :- Bits Int # () :=> (Bits Integer) Instance detailsDefined in Data.Constraint Methodsins :: () :- Bits Integer # () :=> (Bits Natural) Instance detailsDefined in Data.Constraint Methodsins :: () :- Bits Natural # () :=> (Bits Word) Instance detailsDefined in Data.Constraint Methodsins :: () :- Bits Word # Bits a => Bits (Identity a) Instance detailsDefined in Data.Functor.Identity Methods(.&.) :: Identity a -> Identity a -> Identity a #(.|.) :: Identity a -> Identity a -> Identity a #xor :: Identity a -> Identity a -> Identity a #complement :: Identity a -> Identity a #shift :: Identity a -> Int -> Identity a #rotate :: Identity a -> Int -> Identity a #bit :: Int -> Identity a #setBit :: Identity a -> Int -> Identity a #clearBit :: Identity a -> Int -> Identity a #complementBit :: Identity a -> Int -> Identity a #testBit :: Identity a -> Int -> Bool #bitSize :: Identity a -> Int #isSigned :: Identity a -> Bool #shiftL :: Identity a -> Int -> Identity a #unsafeShiftL :: Identity a -> Int -> Identity a #shiftR :: Identity a -> Int -> Identity a #unsafeShiftR :: Identity a -> Int -> Identity a #rotateL :: Identity a -> Int -> Identity a #rotateR :: Identity a -> Int -> Identity a #popCount :: Identity a -> Int # Class (Eq a) (Bits a) Instance detailsDefined in Data.Constraint Methodscls :: Bits a :- Eq a # (Bits a) :=> (Bits (Identity a)) Instance detailsDefined in Data.Constraint Methodsins :: Bits a :- Bits (Identity a) # (Bits a) :=> (Bits (Const a b)) Instance detailsDefined in Data.Constraint Methodsins :: Bits a :- Bits (Const a b) # Bits a => Bits (Const a b) Instance detailsDefined in Data.Functor.Const Methods(.&.) :: Const a b -> Const a b -> Const a b #(.|.) :: Const a b -> Const a b -> Const a b #xor :: Const a b -> Const a b -> Const a b #complement :: Const a b -> Const a b #shift :: Const a b -> Int -> Const a b #rotate :: Const a b -> Int -> Const a b #zeroBits :: Const a b #bit :: Int -> Const a b #setBit :: Const a b -> Int -> Const a b #clearBit :: Const a b -> Int -> Const a b #complementBit :: Const a b -> Int -> Const a b #testBit :: Const a b -> Int -> Bool #bitSizeMaybe :: Const a b -> Maybe Int #bitSize :: Const a b -> Int #isSigned :: Const a b -> Bool #shiftL :: Const a b -> Int -> Const a b #unsafeShiftL :: Const a b -> Int -> Const a b #shiftR :: Const a b -> Int -> Const a b #unsafeShiftR :: Const a b -> Int -> Const a b #rotateL :: Const a b -> Int -> Const a b #rotateR :: Const a b -> Int -> Const a b #popCount :: Const a b -> Int # Bits a => Bits (Tagged s a) Instance detailsDefined in Data.Tagged Methods(.&.) :: Tagged s a -> Tagged s a -> Tagged s a #(.|.) :: Tagged s a -> Tagged s a -> Tagged s a #xor :: Tagged s a -> Tagged s a -> Tagged s a #complement :: Tagged s a -> Tagged s a #shift :: Tagged s a -> Int -> Tagged s a #rotate :: Tagged s a -> Int -> Tagged s a #zeroBits :: Tagged s a #bit :: Int -> Tagged s a #setBit :: Tagged s a -> Int -> Tagged s a #clearBit :: Tagged s a -> Int -> Tagged s a #complementBit :: Tagged s a -> Int -> Tagged s a #testBit :: Tagged s a -> Int -> Bool #bitSizeMaybe :: Tagged s a -> Maybe Int #bitSize :: Tagged s a -> Int #isSigned :: Tagged s a -> Bool #shiftL :: Tagged s a -> Int -> Tagged s a #unsafeShiftL :: Tagged s a -> Int -> Tagged s a #shiftR :: Tagged s a -> Int -> Tagged s a #unsafeShiftR :: Tagged s a -> Int -> Tagged s a #rotateL :: Tagged s a -> Int -> Tagged s a #rotateR :: Tagged s a -> Int -> Tagged s a #popCount :: Tagged s a -> Int #

srl :: Bits b => b -> Int -> b #

Shift Right Logical (i.e., without sign extension)

NB: When used on negative Integers, hilarity may ensue.

toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b #

Attempt to convert an Integral type a to an Integral type b using the size of the types as measured by Bits methods.

A simpler version of this function is:

toIntegral :: (Integral a, Integral b) => a -> Maybe b
toIntegral x
| toInteger x == y = Just (fromInteger y)
| otherwise        = Nothing
where
y = toInteger x

This version requires going through Integer, which can be inefficient. However, toIntegralSized is optimized to allow GHC to statically determine the relative type sizes (as measured by bitSizeMaybe and isSigned) and avoid going through Integer for many types. (The implementation uses fromIntegral, which is itself optimized with rules for base types but may go through Integer for some type pairs.)

Since: base-4.8.0.0

class Bits b => FiniteBits b where #

The FiniteBits class denotes types with a finite, fixed number of bits.

Since: base-4.7.0.0

Minimal complete definition

finiteBitSize

Methods

finiteBitSize :: b -> Int #

Return the number of bits in the type of the argument. The actual value of the argument is ignored. Moreover, finiteBitSize is total, in contrast to the deprecated bitSize function it replaces.

finiteBitSize = bitSize
bitSizeMaybe = Just . finiteBitSize


Since: base-4.7.0.0

countLeadingZeros :: b -> Int #

Count number of zero bits preceding the most significant set bit.

countLeadingZeros (zeroBits :: a) = finiteBitSize (zeroBits :: a)


countLeadingZeros can be used to compute log base 2 via

logBase2 x = finiteBitSize x - 1 - countLeadingZeros x


Note: The default implementation for this method is intentionally naive. However, the instances provided for the primitive integral types are implemented using CPU specific machine instructions.

Since: base-4.8.0.0

countTrailingZeros :: b -> Int #

Count number of zero bits following the least significant set bit.

countTrailingZeros (zeroBits :: a) = finiteBitSize (zeroBits :: a)
countTrailingZeros . negate = countTrailingZeros


The related find-first-set operation can be expressed in terms of countTrailingZeros as follows

findFirstSet x = 1 + countTrailingZeros x


Note: The default implementation for this method is intentionally naive. However, the instances provided for the primitive integral types are implemented using CPU specific machine instructions.

Since: base-4.8.0.0

Instances
 Since: base-4.7.0.0 Instance detailsDefined in Data.Bits Methods Since: base-4.6.0.0 Instance detailsDefined in Data.Bits Methods Since: base-4.6.0.0 Instance detailsDefined in GHC.Int Methods Since: base-4.6.0.0 Instance detailsDefined in GHC.Int Methods Since: base-4.6.0.0 Instance detailsDefined in GHC.Int Methods Since: base-4.6.0.0 Instance detailsDefined in GHC.Int Methods Since: base-4.6.0.0 Instance detailsDefined in Data.Bits Methods Since: base-4.6.0.0 Instance detailsDefined in GHC.Word Methods Since: base-4.6.0.0 Instance detailsDefined in GHC.Word Methods Since: base-4.6.0.0 Instance detailsDefined in GHC.Word Methods Since: base-4.6.0.0 Instance detailsDefined in GHC.Word Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.Ptr Methods Instance detailsDefined in Foreign.Ptr Methods FiniteBits a => FiniteBits (Identity a) Instance detailsDefined in Data.Functor.Identity Methods FiniteBits a => FiniteBits (Const a b) Instance detailsDefined in Data.Functor.Const MethodsfiniteBitSize :: Const a b -> Int #countLeadingZeros :: Const a b -> Int #countTrailingZeros :: Const a b -> Int # FiniteBits a => FiniteBits (Tagged s a) Instance detailsDefined in Data.Tagged MethodsfiniteBitSize :: Tagged s a -> Int #countLeadingZeros :: Tagged s a -> Int #countTrailingZeros :: Tagged s a -> Int #

class (Num t, FiniteBits t) => Ranked t where #

Minimal complete definition

nlz

Methods

lsb :: t -> Int #

Calculate the least significant set bit using a debruijn multiplication table. NB: The result of this function is undefined when given 0.

rank :: t -> Int #

Calculate the number of trailing 0 bits.

nlz :: t -> Int #

Calculate the number of leading zeros.

Instances
 Instance detailsDefined in Data.Bits.Extras Methodslsb :: Int8 -> Int #rank :: Int8 -> Int #nlz :: Int8 -> Int # Instance detailsDefined in Data.Bits.Extras Methodslsb :: Int16 -> Int #rank :: Int16 -> Int #nlz :: Int16 -> Int # Instance detailsDefined in Data.Bits.Extras Methodslsb :: Int32 -> Int #rank :: Int32 -> Int #nlz :: Int32 -> Int # Instance detailsDefined in Data.Bits.Extras Methodslsb :: Int64 -> Int #rank :: Int64 -> Int #nlz :: Int64 -> Int # Instance detailsDefined in Data.Bits.Extras Methodslsb :: Word8 -> Int #rank :: Word8 -> Int #nlz :: Word8 -> Int # Instance detailsDefined in Data.Bits.Extras Methodslsb :: Word16 -> Int #rank :: Word16 -> Int #nlz :: Word16 -> Int # Instance detailsDefined in Data.Bits.Extras Methodslsb :: Word32 -> Int #rank :: Word32 -> Int #nlz :: Word32 -> Int # Instance detailsDefined in Data.Bits.Extras Methodslsb :: Word64 -> Int #rank :: Word64 -> Int #nlz :: Word64 -> Int #

msb :: Ranked t => t -> Int #

Calculate the most significant set bit.

## Optics

(.|.~) :: Bits a => ASetter s t a a -> a -> s -> t infixr 4 #

Bitwise .|. the target(s) of a Lens or Setter.

>>> _2 .|.~ 6 $("hello",3) ("hello",7)  (.|.~) :: Bits a => Setter s t a a -> a -> s -> t (.|.~) :: Bits a => Iso s t a a -> a -> s -> t (.|.~) :: Bits a => Lens s t a a -> a -> s -> t (.|.~) :: (Monoid a, Bits a) => Traversal s t a a -> a -> s -> t  (.&.~) :: Bits a => ASetter s t a a -> a -> s -> t infixr 4 # Bitwise .&. the target(s) of a Lens or Setter. >>> _2 .&.~ 7$ ("hello",254)
("hello",6)

(.&.~) :: Bits a             => Setter s t a a    -> a -> s -> t
(.&.~) :: Bits a             => Iso s t a a       -> a -> s -> t
(.&.~) :: Bits a             => Lens s t a a      -> a -> s -> t
(.&.~) :: (Monoid a, Bits a) => Traversal s t a a -> a -> s -> t


bitAt :: Bits b => Int -> IndexedLens' Int b Bool #

This Lens can be used to access the value of the nth bit in a number.

bitAt n is only a legal Lens into b if 0 <= n < bitSize (undefined :: b).

>>> 16^.bitAt 4
True

>>> 15^.bitAt 4
False

>>> 15 & bitAt 4 .~ True
31

>>> 16 & bitAt 4 .~ False
0


bits :: (Num b, Bits b) => IndexedTraversal' Int b Bool #

Traverse over all bits in a numeric type.

The bit position is available as the index.

>>> toListOf bits (5 :: Word8)
[True,False,True,False,False,False,False,False]


If you supply this an Integer, the result will be an infinite Traversal, which can be productively consumed, but not reassembled.