Java Float to Byte Array floatToByteArray(float number)

Here you can find the source of floatToByteArray(float number)

Description

float to byte array

License

Apache License

Parameter

Parameter Description
number a parameter

Return

byte[]

Declaration

public static byte[] floatToByteArray(float number) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from w  w w . j  ava2s .  c  o  m
     * float to byte array
     * 
     * @param number
     * @return byte[]
     */
    public static byte[] floatToByteArray(float number) {
        byte[] byteArray = new byte[4];
        Integer intBits = Float.floatToIntBits(number);
        for (int i = 0; i < byteArray.length; i++) {
            byteArray[i] = new Integer(intBits).byteValue();
            intBits = intBits >> 8;
        }
        return byteArray;
    }
}

Related

  1. floatToByte(float[] values)
  2. floatToByteArray(float source)
  3. floatToByteArray(float value)
  4. floatToByteArrayBE(float data)
  5. floatToBytes(final float f)