Aman Jaiswal
Aman Jaiswal

Reputation: 1093

Convert kth bit from last

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

Answers (1)

Julia Path
Julia Path

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

Related Questions