Java Float Number Create toFloatA(byte[] data)

Here you can find the source of toFloatA(byte[] data)

Description

to Float A

License

Open Source License

Declaration

public static float[] toFloatA(byte[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static float[] toFloatA(byte[] data) {
        if (data == null || data.length % 4 != 0)
            return null;
        // ----------
        float[] flts = new float[data.length / 4];
        for (int i = 0; i < flts.length; i++) {
            flts[i] = toFloat(new byte[] { data[(i * 4)],
                    data[(i * 4) + 1], data[(i * 4) + 2],
                    data[(i * 4) + 3], });
        }// w ww  .  j a  va 2 s  .c o  m
        return flts;
    }

    public static float toFloat(byte[] data) {
        if (data == null || data.length != 4)
            return 0x0;
        // ---------- simple:
        return Float.intBitsToFloat(toInt(data));
    }

    public static int toInt(byte[] data) {
        if (data == null || data.length != 4)
            return 0x0;
        // ----------
        return (int) ( // NOTE: type cast not necessary for int
        (0xff & data[0]) << 24 | (0xff & data[1]) << 16
                | (0xff & data[2]) << 8 | (0xff & data[3]) << 0);
    }
}

Related

  1. toFloat(String value)
  2. toFloat(String value, float _default)
  3. toFloat(String value, Float defaultValue)
  4. toFloat(String value, float defaultValue)
  5. toFloat(T value)
  6. toFloatObject(Object o)