Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { private static final int FLOAT_SIZE = 4; private static final int BITS_IN_BYTE = 8; /** * Util method that converts a float into a byte array using a buffer. * * @param buffer The buffer to put the converted float * @param pos The position to start putting the converted float * @param input The float to convert */ public static void putFloatToBytes(byte[] buffer, int pos, float input) { /* Get the integer representation in order bitwise operations */ int value = Float.floatToIntBits(input); /* Convert the float into array of bytes */ for (int i = pos; i < pos + FLOAT_SIZE; i++) { buffer[i] = (byte) (value >> (((FLOAT_SIZE - 1) - (i - pos)) * BITS_IN_BYTE)); } } }