Created
September 30, 2011 15:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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