I have the following code:
(defn BitScanReverse [^Long bit-board]
(loop [value bit-board r 0]
(cond
(> value 0x00000000FFFFFFFF) (recur (unsigned-bit-shift-right value 32) (+ r 32))
(> value 0x000000000000FFFF) (recur (unsigned-bit-shift-right value 16) (+ r 16))
(> value 0x00000000000000FF) (recur (unsigned-bit-shift-right value 8) (+ r 8))
(> value 0x000000000000000F) (recur (unsigned-bit-shift-right value 4) (+ r 4))
(> value 0x0000000000000003) (recur (unsigned-bit-shift-right value 2) (+ r 2))
(> value 0x0000000000000001) (recur (unsigned-bit-shift-right value 1) (+ r 1))
:else r)))
It returns the index of the last bit found in a bitboard. The problems is when I try to run: (BitScanReverse 18446462598732840960) ;;Expecting 63. Its gives me: IllegalArgumentException Value out of range for long: 18446462598732840960 clojure.lang.RT.longCast (RT.java:1134)
This bitboard is the initial position of the black pieces. The problem is that long is signed in clojure (and also in java). I've tried to use BigInt but it doesn't allow bit operations.
Any suggestions?