module Bitwise
(
and,
or,
xor,
complement,
shiftLeftBy,
shiftRightBy,
shiftRightZfBy,
)
where
import Basics (Int)
import Data.Bits ((.&.), (.|.))
import qualified Data.Bits
import qualified Prelude
and :: Int -> Int -> Int
and :: Int -> Int -> Int
and = Int -> Int -> Int
forall a. Bits a => a -> a -> a
(.&.)
or :: Int -> Int -> Int
or :: Int -> Int -> Int
or = Int -> Int -> Int
forall a. Bits a => a -> a -> a
(.|.)
xor :: Int -> Int -> Int
xor :: Int -> Int -> Int
xor = Int -> Int -> Int
forall a. Bits a => a -> a -> a
Data.Bits.xor
complement :: Int -> Int
complement :: Int -> Int
complement = Int -> Int
forall a. Bits a => a -> a
Data.Bits.complement
shiftLeftBy :: Int -> Int -> Int
shiftLeftBy :: Int -> Int -> Int
shiftLeftBy Int
offset Int
value =
Int -> Int -> Int
forall a. Bits a => a -> Int -> a
Data.Bits.shift Int
value (Int -> Int
forall a b. (Integral a, Num b) => a -> b
Prelude.fromIntegral Int
offset)
shiftRightBy :: Int -> Int -> Int
shiftRightBy :: Int -> Int -> Int
shiftRightBy Int
offset Int
value =
Int -> Int -> Int
forall a. Bits a => a -> Int -> a
Data.Bits.shiftR Int
value (Int -> Int
forall a b. (Integral a, Num b) => a -> b
Prelude.fromIntegral Int
offset)
shiftRightZfBy :: Int -> Int -> Int
shiftRightZfBy :: Int -> Int -> Int
shiftRightZfBy Int
offset Int
value =
let n :: Int
n = Int -> Int
forall a b. (Integral a, Num b) => a -> b
Prelude.fromIntegral Int
offset
oneBits :: Int
oneBits = Int -> Int
forall a. Bits a => a -> a
Data.Bits.complement Int
forall a. Bits a => a
Data.Bits.zeroBits :: Int
shiftedValue :: Int
shiftedValue = Int -> Int -> Int
forall a. Bits a => a -> Int -> a
Data.Bits.shiftR Int
value Int
n
shiftedMask :: Int
shiftedMask = Int -> Int -> Int
forall a. Bits a => a -> Int -> a
Data.Bits.rotateR (Int -> Int -> Int
forall a. Bits a => a -> Int -> a
Data.Bits.shiftL Int
oneBits Int
n) Int
n
in Int -> Int -> Int
and Int
shiftedValue Int
shiftedMask