Skip to content

Instantly share code, notes, and snippets.

@quiye
Created April 11, 2018 13:34
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 quiye/b09808212c2f692044069267fcd90914 to your computer and use it in GitHub Desktop.
Save quiye/b09808212c2f692044069267fcd90914 to your computer and use it in GitHub Desktop.
4bytes => Float
scala> import java.nio.ByteBuffer
import java.nio.ByteBuffer
scala> val b = Array(1,2,3,4,5,6,7,8,0,0,0,0).map(_.toByte)
b: Array[Byte] = Array(1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0)
scala> b.grouped(4).foldRight(Nil: List[Float])(ByteBuffer.wrap(_).getFloat::_)
res8: List[Float] = List(2.3879393E-38, 6.301941E-36, 0.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment