The java.lang.Float class has methods floatToIntBits() and floatToRawIntBits() , which you can use to get the float bitmap (as an int ). So you can do something like this:
float value = 1.5e-3f; int bits = Float.floatToIntBits(value); byte[] bytes = new byte[4]; bytes[0] = (byte)(bits & 0xff); bytes[1] = (byte)((bits >> 8) & 0xff); bytes[2] = (byte)((bits >> 16) & 0xff); bytes[3] = (byte)((bits >> 24) & 0xff);
Note. You will need to find for your specific application which of floatToIntBits() or floatToRawIntBits() is suitable, and you will need to determine in which order you need bytes (small or large end).
source share