Reputation: 1093
Hi I am new in haskell.
Can any one tell me to convert Kth bit from last of given Integer in haskell.
For n = 37 and k = 3, the output should be killKthBit(n, k) = 33.
37 = 100101 ~> 100001 = 33.
Upvotes: 1
Views: 56
Reputation: 2366
You are looking for the Bits
typeclass in Data.Bits
. Integer has an instance for Bits
, so you can:
clearBit 37 2 -- 2 because we are indexing from 0.
Upvotes: 1