Skip to content

Instantly share code, notes, and snippets.

@pbiggar
Created August 16, 2016 22:59
Show Gist options
  • Save pbiggar/6c85a771230a9b02b99d0a9d146c0b27 to your computer and use it in GitHub Desktop.
Save pbiggar/6c85a771230a9b02b99d0a9d146c0b27 to your computer and use it in GitHub Desktop.
module Bitwise (bw) where
import Data.Bits((.&.), bit, testBit)
bw :: Int -> Int -> Int
bw l r = bwf l r 63 0
bwf :: Int -> Int -> Int -> Int -> Int
bwf l r 0 accum = accum
bwf l r i accum
| testBit l i == testBit r i = bwf l r (i-1) (accum + ((bit i) .&. l))
| otherwise = accum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment