Here you can find the source of getBytes(ByteBuffer floatCalculator, float number)
Parameter | Description |
---|---|
floatCalculator | Buffer to do the conversion |
number | The float value |
public static byte[] getBytes(ByteBuffer floatCalculator, float number)
//package com.java2s; //License from project: LGPL import java.nio.ByteBuffer; public class Main { /**/* w w w.j a va 2 s . co m*/ * Calculates the 4 sequential bytes given the corresponding float value * @param floatCalculator Buffer to do the conversion * @param number The float value * @return The corresponding sequence of 4 bytes */ public static byte[] getBytes(ByteBuffer floatCalculator, float number) { byte[] bytes = new byte[4]; floatCalculator.clear(); floatCalculator.putFloat(number); floatCalculator.position(0); floatCalculator.get(bytes); return bytes; } /** * Calculates the 4 sequential bytes given the corresponding float value * @param longCalculator Buffer to do the conversion * @param number The float value * @return The corresponding sequence of 4 bytes */ public static byte[] getBytes(ByteBuffer longCalculator, long number) { byte[] bytes = new byte[8]; longCalculator.clear(); longCalculator.putLong(number); longCalculator.position(0); longCalculator.get(bytes); return bytes; } /** * Calculates the 4 sequential bytes given the corresponding integer value. * @param intCalculator Buffer to do the conversion * @param number The integer value * @return The corresponding sequence of 4 bytes */ public static byte[] getBytes(ByteBuffer intCalculator, int number) { byte[] bytes = new byte[4]; intCalculator.clear(); intCalculator.putInt(number); intCalculator.position(0); intCalculator.get(bytes); return bytes; } }