I\'m trying to convert a byte[] to a float[] by putting the byte[] in a ByteBuffer, converting this to a FloatBuffer (.asFloatBuffer
), and then converting this to a
private static float[] toFloatArray(byte[] bytes) {
ByteBuffer buffer = ByteBuffer.wrap(bytes);
FloatBuffer fb = buffer.asFloatBuffer();
float[] floatArray = new float[fb.limit()];
fb.get(floatArray);
return floatArray;
}
ex:
byte[] bytes = {65,-56,0,0 , 65,-56,0,0};
float[] result = toFloatArray(bytes);
//print 25.0 25.0
System.out.println(Arrays.toString(result));