Created
August 16, 2016 22:59
-
-
Save pbiggar/6c85a771230a9b02b99d0a9d146c0b27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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