Created
July 21, 2016 14:05
-
-
Save tonyonodi/ff2d87bdf87e72b7d1cd075f48c3867d to your computer and use it in GitHub Desktop.
Convert byte array to integer in Clojure
This file contains hidden or 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
; Adapted from http://stackoverflow.com/a/13041851/3122246 the way it goes about converting (converts to list of | |
; strings, then to a string then reads the string) is kind of ugly but the code is nice at least. | |
(defn bytes->int [bytes] | |
"Converts a byte array into an integer." | |
(->> | |
bytes | |
(map (partial format "%02x")) | |
(apply (partial str "0x")) | |
read-string)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment