Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created June 25, 2011 18:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sritchie/1046756 to your computer and use it in GitHub Desktop.
(defn flipped-endian-float
"Flips the endian order of the supplied byte sequence, and converts
the sequence into a float."
[bitseq]
(Float/intBitsToFloat
(reduce +
(map-indexed (fn [idx bit]
(bit-shift-left
(bit-and bit 0xff)
(* 8 idx)))
bitseq))))
(defn flipped-endian-float
"Flips the endian order of the supplied byte sequence, and converts
the sequence into a float."
[bitseq]
(->> bitseq
(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