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 import Prelude -- To generate the dependency
14 #ifdef __GLASGOW_HASKELL__
20 --ADR: The fixity for .|. conflicts with that for .|. in Fran.
21 -- Removing all fixities is a fairly safe fix; fixing the "one fixity
22 -- per symbol per program" limitation in Hugs would take a lot longer.
24 infixl 8 `shift`, `rotate`
30 class Num a => Bits a where
31 (.&.), (.|.), xor :: a -> a -> a
33 shift :: a -> Int -> a
34 rotate :: a -> Int -> a
36 setBit :: a -> Int -> a
37 clearBit :: a -> Int -> a
38 complementBit :: a -> Int -> a
39 testBit :: a -> Int -> Bool
44 setBit x i = x .|. bit i
45 clearBit x i = x .&. complement (bit i)
46 complementBit x i = x `xor` bit i
47 testBit x i = (x .&. bit i) /= 0
49 shiftL, shiftR :: Bits a => a -> Int -> a
50 rotateL, rotateR :: Bits a => a -> Int -> a
51 shiftL a i = shift a i
52 shiftR a i = shift a (-i)
53 rotateL a i = rotate a i
54 rotateR a i = rotate a (-i)