Java examples for java.nio:ByteBuffer Convert
Converts a byte array to a float via ByteBuffer.
//package com.java2s; import java.nio.ByteBuffer; public class Main { public static void main(String[] argv) throws Exception { byte[] b = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(byteArrayToFloat(b)); }/* w w w . ja v a 2s .c om*/ /** * Converts a byte array to a float. * @param b - The byte array. Must be a length of at least 4. * @return The float. */ public static float byteArrayToFloat(byte[] b) { return ByteBuffer.wrap(b).getFloat(); } }