Skip to content

Instantly share code, notes, and snippets.

@tomjack
Created October 14, 2009 03:10
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 tomjack/223d4f377d4b3e7d6dab to your computer and use it in GitHub Desktop.
Save tomjack/223d4f377d4b3e7d6dab to your computer and use it in GitHub Desktop.
(defn btwoc* [sofar n]
(if (zero? n)
(let [first-char (first sofar)]
(if (or (and first-char (bit-test (int first-char) 7))
(empty? sofar))
(conj sofar (char 0))
sofar))
(recur (conj sofar (char (bit-and n 0xFF)))
(bit-shift-right n 8))))
(defn btwoc [n]
(apply str (btwoc* '() n)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment