Convert byte array to float in Java
Description
The following code shows how to convert byte array to float.
Example
// www. j a v a 2 s . c om
import java.nio.ByteBuffer;
public class Main {
public static float convertToFloat(byte[] array) {
ByteBuffer buffer = ByteBuffer.wrap(array);
return buffer.getFloat();
}
public static void main(String[] argv){
System.out.println(convertToFloat(new byte[]{1,2,35,6,7,8,9,8,7,6,6,}));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »