Skip to content

Instantly share code, notes, and snippets.

@m0smith
Created September 30, 2011 15:46
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 m0smith/1254165 to your computer and use it in GitHub Desktop.
Save m0smith/1254165 to your computer and use it in GitHub Desktop.
convert a long into a sequence of 8 bytes. The zeroes are padded to the beginning to make the BigIntger constructor happy
(defn long-to-bytes
"convert a long into a sequence of 8 bytes. The zeroes are padded to the
beginning to make the BigInteger contructor happy" [^long lng]
(let [pad (repeat 8 (byte 0))
bytes (map byte (.. (BigInteger/valueOf lng) toByteArray))]
(concat (drop (count bytes) pad) bytes)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment