Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
;; 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
You can’t perform that action at this time.