home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 876 / hugs.sis / Bits.hs < prev    next >
Encoding:
Text File  |  2000-09-21  |  1.1 KB  |  37 lines

  1. -----------------------------------------------------------------------------
  2. -- Bit twiddling operations
  3. --
  4. -- This library defines bitwise operations for signed and unsigned ints.
  5. --
  6. -- Suitable for use with Hugs 98.
  7. -----------------------------------------------------------------------------
  8.  
  9. module Bits where
  10.  
  11. infixl 8 `shift`, `rotate`
  12. infixl 7 .&.
  13. infixl 6 `xor`
  14. infixl 5 .|.
  15.  
  16. class Bits a where
  17.   (.&.), (.|.), xor :: a -> a -> a
  18.   complement        :: a -> a
  19.   shift             :: a -> Int -> a
  20.   rotate            :: a -> Int -> a
  21.   bit               :: Int -> a        
  22.   setBit            :: a -> Int -> a   
  23.   clearBit          :: a -> Int -> a   
  24.   complementBit     :: a -> Int -> a   
  25.   testBit           :: a -> Int -> Bool
  26.   bitSize           :: a -> Int
  27.   isSigned          :: a -> Bool
  28.  
  29. shiftL, shiftR   :: Bits a => a -> Int -> a
  30. rotateL, rotateR :: Bits a => a -> Int -> a
  31. shiftL  a i = shift  a i
  32. shiftR  a i = shift  a (-i)
  33. rotateL a i = rotate a i
  34. rotateR a i = rotate a (-i)
  35.  
  36. -----------------------------------------------------------------------------
  37.