5 This library defines bitwise operations for signed and unsigned ints.
9 infixl 8 `shift`, `rotate`
15 (.&.), (.|.), xor :: a -> a -> a
17 shift :: a -> Int -> a
18 rotate :: a -> Int -> a
20 setBit :: a -> Int -> a
21 clearBit :: a -> Int -> a
22 complementBit :: a -> Int -> a
23 testBit :: a -> Int -> Bool
27 shiftL, shiftR :: Bits a => a -> Int -> a
28 rotateL, rotateR :: Bits a => a -> Int -> a
29 shiftL a i = shift a i
30 shiftR a i = shift a (-i)
31 rotateL a i = rotate a i
32 rotateR a i = rotate a (-i)
38 <tt/bitSize/ and <tt/isSigned/ are like <tt/floatRadix/ and
39 <tt/floatDigits/ -- they return parameters of the <em/type/ of their
40 argument rather than of the particular argument they are applied to.
41 <tt/bitSize/ returns the number of bits in the type; and
42 <tt/isSigned/ returns whether the type is signed or not.
44 <tt/shift/ performs sign extension on signed number types.
45 That is, right shifts fill the top bits with 1 if the number is negative
48 Bits are numbered from 0 with bit 0 being the least significant bit.
50 <tt/shift x i/ and <tt/rotate x i/ shift to the left if <tt/i/ is
51 positive and to the right otherwise.
54 <tt/rotate/ is well defined only if bitSize returns a number.
55 (Maybe we should impose a Bounded constraint on it?)
58 <tt/bit i/ is the value with the i'th bit set.