-
-
Save kno3comma14/b3921a0fb631ffd562d44708d8818467 to your computer and use it in GitHub Desktop.
Clojure code to convert a byte array to an integer
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
| (defn bytes-to-int | |
| ([bytes] | |
| (bytes-to-int bytes 0)) | |
| ([bytes offset] | |
| (reduce + 0 | |
| (map (fn [i] | |
| (let [shift (* (- 4 1 i) | |
| 8)] | |
| (bit-shift-left (bit-and (nth bytes (+ i offset)) | |
| 0x000000FF) | |
| shift))) | |
| (range 0 4))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment