Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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