Created
July 30, 2011 21:38
-
-
Save sritchie/1116033 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 flipped-endian-float | |
"Flips the endian order of each byte in the supplied byte sequence, | |
and converts the sequence into a float. Currently we limit the size | |
of the `byte-seq` to 4." | |
[byte-seq] | |
{:pre [(= 4 (count byte-seq))]} | |
(->> byte-seq | |
(map-indexed (fn [idx bit] | |
(bit-shift-left | |
(bit-and bit 0xff) | |
(* 8 idx)))) | |
(reduce +) | |
(Float/intBitsToFloat))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment