Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created July 30, 2011 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/1116033 to your computer and use it in GitHub Desktop.
Save sritchie/1116033 to your computer and use it in GitHub Desktop.
(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