Created
March 21, 2011 13:54
-
-
Save jorisbontje/879473 to your computer and use it in GitHub Desktop.
This file contains 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
;; Logical / unsigned shift right in Clojure (>>> operator in Java) | |
;; | |
;; Algorithm from http://www.sitepoint.com/forums/php-34/unsigned-right-bitwise-shift-449434.html | |
(defn logical-shift-right [n s] | |
(if (neg? n) | |
(bit-or (bit-shift-right (bit-and n 0x7fffffff) s) | |
(bit-shift-right 0x40000000 (dec s))) | |
(bit-shift-right n s))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment