Created
March 23, 2011 15:56
-
-
Save sritchie/883338 to your computer and use it in GitHub Desktop.
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 little-float | |
"Converts the supplied byte sequence into a float, in little endian | |
format." | |
[bitseq] | |
(->> bitseq | |
(map-indexed (fn [idx bit] | |
(-> (bit-and bit 0xff) | |
(bit-shift-left (* 8 idx))))) | |
(reduce bit-xor) | |
(Float/intBitsToFloat))) | |
(defn little-float | |
"Converts the supplied byte sequence into a float, in little endian | |
format." | |
[bitseq] | |
(->> bitseq | |
(map-indexed (fn [idx bit] | |
(bit-shift-left | |
(bit-and bit 0xff) | |
(* 8 idx)))) | |
(reduce bit-xor) | |
(Float/intBitsToFloat))) | |
(defn little-floats | |
"Converts the supplied byte array into a seq of | |
little-endian-ordered floats." | |
[bytes] | |
(vec (map little-float | |
(partition float-bytes bytes)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment