Skip to content

Instantly share code, notes, and snippets.

@m0smith
Created September 30, 2011 15:46
Show Gist options
  • 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