Here you can find the source of floatToBytes(float fnum, byte[] bytes, int startIndex)
Parameter | Description |
---|---|
num | the float to be translated |
bytes | [] the byte array |
startIndex | starting to store in this index |
public static int floatToBytes(float fnum, byte[] bytes, int startIndex)
//package com.java2s; //License from project: Open Source License public class Main { /**//from ww w. ja va 2s . c o m * translate float into bytes, stored in byte array starting from startIndex * * @param num * the float to be translated * @param bytes * [] the byte array * @param startIndex * starting to store in this index * @ret the index of the cell after storing the number. */ public static int floatToBytes(float fnum, byte[] bytes, int startIndex) { return intToBytes(Float.floatToIntBits(fnum), bytes, startIndex); } /** * translate int into bytes, stored in byte array starting from startIndex * * @param num * the integer to be translated * @param bytes * [] the byte array * @param startIndex * starting to store in this index * @ret the index of the cell after storing the number. */ public static int intToBytes(int num, byte[] bytes, int startIndex) { bytes[startIndex] = (byte) (num & 0xff); bytes[startIndex + 1] = (byte) ((num >> 8) & 0xff); bytes[startIndex + 2] = (byte) ((num >> 16) & 0xff); bytes[startIndex + 3] = (byte) ((num >> 24) & 0xff); return startIndex + 4; } }