Skip to content

Instantly share code, notes, and snippets.

@tonyonodi
Created July 21, 2016 14:05
Show Gist options
  • Save tonyonodi/ff2d87bdf87e72b7d1cd075f48c3867d to your computer and use it in GitHub Desktop.
Save tonyonodi/ff2d87bdf87e72b7d1cd075f48c3867d to your computer and use it in GitHub Desktop.
Convert byte array to integer in Clojure
; 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