Skip to content

Instantly share code, notes, and snippets.

@jorisbontje
Created March 21, 2011 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorisbontje/879473 to your computer and use it in GitHub Desktop.
Save jorisbontje/879473 to your computer and use it in GitHub Desktop.
;; 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