2 % (c) The GRASP/AQUA Project, Glasgow University, 1998-2000
4 \section[Bits]{The @Bits@ interface}
6 Defines the @Bits@ class containing bit-based operations.
7 See library document for details on the semantics of the
13 #ifdef __GLASGOW_HASKELL__
19 --ADR: The fixity for .|. conflicts with that for .|. in Fran.
20 -- Removing all fixities is a fairly safe fix; fixing the "one fixity
21 -- per symbol per program" limitation in Hugs would take a lot longer.
23 infixl 8 `shift`, `rotate`
29 class Num a => Bits a where
30 (.&.), (.|.), xor :: a -> a -> a
32 shift :: a -> Int -> a
33 rotate :: a -> Int -> a
35 setBit :: a -> Int -> a
36 clearBit :: a -> Int -> a
37 complementBit :: a -> Int -> a
38 testBit :: a -> Int -> Bool
43 setBit x i = x .|. bit i
44 clearBit x i = x .&. complement (bit i)
45 complementBit x i = x `xor` bit i
46 testBit x i = (x .&. bit i) /= 0
48 shiftL, shiftR :: Bits a => a -> Int -> a
49 rotateL, rotateR :: Bits a => a -> Int -> a
50 shiftL a i = shift a i
51 shiftR a i = shift a (-i)
52 rotateL a i = rotate a i
53 rotateR a i = rotate a (-i)