haskell2010-base
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Bits

Description

This module defines bitwise operations for signed and unsigned integers.

Synopsis

Documentation

class Num 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: .&., .|., xor, complement, (shift or (shiftL and shiftR)), (rotate or (rotateL and rotateR)), bitSize and isSigned.

Methods

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

Bitwise "and"

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

Bitwise "or"

xor :: a -> a -> a #

Bitwise "xor"

complement :: a -> a #

Reverse all the bits in the argument

shift :: a -> Int -> a #

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 #

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.

bit :: Int -> a #

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

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

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 #

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.

shiftR :: a -> Int -> a #

Shift the first argument right by the specified number of bits (which must be non-negative). 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.

rotateL :: a -> Int -> a #

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 #

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.

Instances

Instances details
Bits Int # 
Instance details

Defined in Data.Bits

Methods

(.&.) :: Int -> Int -> Int #

(.|.) :: Int -> Int -> Int #

xor :: Int -> Int -> Int #

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

shiftR :: Int -> Int -> Int #

rotateL :: Int -> Int -> Int #

rotateR :: Int -> Int -> Int #

Bits Int16 # 
Instance details

Defined in Data.Bits

Bits Int32 # 
Instance details

Defined in Data.Bits

Bits Int64 # 
Instance details

Defined in Data.Bits

Bits Int8 # 
Instance details

Defined in Data.Bits

Methods

(.&.) :: Int8 -> Int8 -> Int8 #

(.|.) :: Int8 -> Int8 -> Int8 #

xor :: Int8 -> Int8 -> Int8 #

complement :: Int8 -> Int8 #

shift :: Int8 -> Int -> Int8 #

rotate :: Int8 -> Int -> Int8 #

bit :: Int -> Int8 #

setBit :: Int8 -> Int -> Int8 #

clearBit :: Int8 -> Int -> Int8 #

complementBit :: Int8 -> Int -> Int8 #

testBit :: Int8 -> Int -> Bool #

bitSize :: Int8 -> Int #

isSigned :: Int8 -> Bool #

shiftL :: Int8 -> Int -> Int8 #

shiftR :: Int8 -> Int -> Int8 #

rotateL :: Int8 -> Int -> Int8 #

rotateR :: Int8 -> Int -> Int8 #

Bits Word # 
Instance details

Defined in Data.Bits

Methods

(.&.) :: Word -> Word -> Word #

(.|.) :: Word -> Word -> Word #

xor :: Word -> Word -> Word #

complement :: Word -> Word #

shift :: Word -> Int -> Word #

rotate :: Word -> Int -> Word #

bit :: Int -> Word #

setBit :: Word -> Int -> Word #

clearBit :: Word -> Int -> Word #

complementBit :: Word -> Int -> Word #

testBit :: Word -> Int -> Bool #

bitSize :: Word -> Int #

isSigned :: Word -> Bool #

shiftL :: Word -> Int -> Word #

shiftR :: Word -> Int -> Word #

rotateL :: Word -> Int -> Word #

rotateR :: Word -> Int -> Word #

Bits Word16 # 
Instance details

Defined in Data.Bits

Bits Word32 # 
Instance details

Defined in Data.Bits

Bits Word64 # 
Instance details

Defined in Data.Bits

Bits Word8 # 
Instance details

Defined in Data.Bits

Bits CChar # 
Instance details

Defined in Foreign.C.Types

Bits CInt # 
Instance details

Defined in Foreign.C.Types

Methods

(.&.) :: CInt -> CInt -> CInt #

(.|.) :: CInt -> CInt -> CInt #

xor :: CInt -> CInt -> CInt #

complement :: CInt -> CInt #

shift :: CInt -> Int -> CInt #

rotate :: CInt -> Int -> CInt #

bit :: Int -> CInt #

setBit :: CInt -> Int -> CInt #

clearBit :: CInt -> Int -> CInt #

complementBit :: CInt -> Int -> CInt #

testBit :: CInt -> Int -> Bool #

bitSize :: CInt -> Int #

isSigned :: CInt -> Bool #

shiftL :: CInt -> Int -> CInt #

shiftR :: CInt -> Int -> CInt #

rotateL :: CInt -> Int -> CInt #

rotateR :: CInt -> Int -> CInt #

Bits CIntMax # 
Instance details

Defined in Foreign.C.Types

Bits CIntPtr # 
Instance details

Defined in Foreign.C.Types

Bits CLLong # 
Instance details

Defined in Foreign.C.Types

Bits CLong # 
Instance details

Defined in Foreign.C.Types

Bits CPtrdiff # 
Instance details

Defined in Foreign.C.Types

Bits CSChar # 
Instance details

Defined in Foreign.C.Types

Bits CShort # 
Instance details

Defined in Foreign.C.Types

Bits CSigAtomic # 
Instance details

Defined in Foreign.C.Types

Bits CSize # 
Instance details

Defined in Foreign.C.Types

Bits CUChar # 
Instance details

Defined in Foreign.C.Types

Bits CUInt # 
Instance details

Defined in Foreign.C.Types

Bits CUIntMax # 
Instance details

Defined in Foreign.C.Types

Bits CUIntPtr # 
Instance details

Defined in Foreign.C.Types

Bits CULLong # 
Instance details

Defined in Foreign.C.Types

Bits CULong # 
Instance details

Defined in Foreign.C.Types

Bits CUShort # 
Instance details

Defined in Foreign.C.Types

Bits CWchar # 
Instance details

Defined in Foreign.C.Types

Bits IntPtr # 
Instance details

Defined in Foreign.Ptr

Bits WordPtr # 
Instance details

Defined in Foreign.Ptr

Bits Integer # 
Instance details

Defined in Data.Bits