Android Float to Byte Array Convert FloatToByte(float f)

Here you can find the source of FloatToByte(float f)

Description

Float To Byte

Declaration

public static byte[] FloatToByte(float f) 

Method Source Code

//package com.java2s;

public class Main {
    public static byte[] FloatToByte(float f) {
        return IntToByte(Float.floatToIntBits(f));
    }//from ww w  .j a v  a 2s. c  o  m

    public static byte[] IntToByte(int i) {
        byte[] result = new byte[4];
        result[0] = (byte) ((i >> 24) & 0xFF);
        result[1] = (byte) ((i >> 16) & 0xFF);
        result[2] = (byte) ((i >> 8) & 0xFF);
        result[3] = (byte) (i & 0xFF);
        return result;
    }
}

Related

  1. float2bytesBE(float val, byte[] b, int off)
  2. float2bytesLE(float val, byte[] b, int off)
  3. floatToBytes(float value)
  4. floats2bytesBE(float[] val)