Here you can find the source of toFloatByteArray(float val, ByteOrder outOrder, byte[] buf, int off)
public static final int toFloatByteArray(float val, ByteOrder outOrder, byte[] buf, int off) throws NumberFormatException
//package com.java2s; /*/*from w w w.j a v a2 s.co m*/ * Copyright 2013 Lyor Goldstein * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.nio.ByteOrder; public class Main { public static final int toFloatByteArray(float val, ByteOrder outOrder, byte[] buf, int off) throws NumberFormatException { return toInt32ByteArray(Float.floatToIntBits(val), outOrder, buf, off); } public static final int toFloatByteArray(float val, ByteOrder outOrder, byte[] buf) throws NumberFormatException { return toFloatByteArray(val, outOrder, buf, 0); } public static final byte[] toFloatByteArray(float val, ByteOrder outOrder) throws NumberFormatException { return toInt32ByteArray(Float.floatToIntBits(val), outOrder); } public static final int toInt32ByteArray(final int val, final ByteOrder outOrder, final byte[] buf, final int off) throws NumberFormatException { if (null == outOrder) throw new NumberFormatException("toInt32ByteArray(" + val + ") no order specified"); final boolean isBigEndian = ByteOrder.BIG_ENDIAN.equals(outOrder); buf[off] = (byte) ((isBigEndian ? (val >> 24) : val) & 0x00FF); buf[off + 1] = (byte) ((isBigEndian ? (val >> 16) : (val >> 8)) & 0x00FF); buf[off + 2] = (byte) ((isBigEndian ? (val >> 8) : (val >> 16)) & 0x00FF); buf[off + 3] = (byte) ((isBigEndian ? val : (val >> 24)) & 0x00FF); return 4; } public static final int toInt32ByteArray(final int val, final ByteOrder outOrder, final byte[] buf) throws NumberFormatException { return toInt32ByteArray(val, outOrder, buf, 0); } public static final byte[] toInt32ByteArray(final int val, final ByteOrder outOrder) throws NumberFormatException { final byte[] data = new byte[4]; final int eLen = toInt32ByteArray(val, outOrder, data); if (eLen != data.length) throw new NumberFormatException("toInt32ByteArray(" + val + ")[" + outOrder + "] unexpected used length: expected=" + data.length + "/got=" + eLen); return data; } }