1.9 KiB
1.9 KiB
Bits
{-# LANGUAGE BinaryLiterals #-}
42 = 0b101010
Bit Operations
.&.
(.&.) :: Bits a => a -> a -> a
Example:
.|.
(.|.) :: Bits a => a -> a -> a
Example:
xor
xor :: Bits a => a -> a -> a
Example:
> True `xor` False
True
> True `xor` True
False
> 0b101 `xor` 0b011
6 -- 0b110
complement
complement :: Bits a => a -> a
> complement True
False
> complement 0b101
-2 -- -0b010
Example:
shift
Example:
shift :: Bits a => a -> Int -> a
Example:
rotate
rotate :: Bits a => a -> Int -> a
Example:
zeroBits
zeroBits :: Bits a => a
Example:
bit
bit :: Bits a => Int -> a
Example:
Bit Testing
setBit :: Bits a => a -> Int -> a
clearBit :: Bits a => a -> Int -> a
complementBit
complementBit :: Bits a => a -> Int -> a
Example:
λ> 0b100 `complementBit` 1
6 -- 0b110
testBit
testBit :: Bits a => a -> Int -> Bool
Example:
> 0b10 `testBit` 0
False
> 0b10 `testBit` 1
True
isSigned
isSigned :: Bits a => a -> Bool
> isSigned 42
True
> isSigned True
False
Bit Size
bitSize :: Bits a => a -> Int
popCount :: Bits a => a -> Int
Bit Shifting
shiftL :: Bits a => a -> Int -> a
shiftR :: Bits a => a -> Int -> a
Bit Rotation
rotate :: Bits a => a -> Int -> a
rotateL :: Bits a => a -> Int -> a
rotateR :: Bits a => a -> Int -> a
Byte Swapping
byteSwap16 :: Word16 -> Word16
byteSwap32 :: Word32 -> Word32
byteSwap64 :: Word64 -> Word64