Java Float Number Create toFloat(byte[] b, int off, boolean bigEndian)

Here you can find the source of toFloat(byte[] b, int off, boolean bigEndian)

Description

to Float

License

Open Source License

Declaration

public static float toFloat(byte[] b, int off, boolean bigEndian) 

Method Source Code

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

public class Main {
    public static float toFloat(byte[] b, int off, boolean bigEndian) {
        return Float.intBitsToFloat(toInt(b, off, bigEndian));
    }// w  w w .  j  a  v a2 s.  c o m

    public static void toFloat(float[] f, int fOff, byte[] b, int bOff, int bLen, boolean bigEndian) {
        int bEnd = bOff + bLen;
        for (int j = bOff, k = fOff; j < bEnd; j += 4, k++) {
            f[k] = toFloat(b, j, bigEndian);
        }
    }

    public static int toInt(byte[] b, int off, boolean bigEndian) {
        if (bigEndian) {
            return ((b[0] & 0xff) << 24) | ((b[1] & 0xff) << 16) | ((b[2] & 0xff) << 8) | ((b[3] & 0xff));
        } else {
            return ((b[3] & 0xff) << 24) | ((b[2] & 0xff) << 16) | ((b[1] & 0xff) << 8) | ((b[0] & 0xff));
        }
    }

    public static void toInt(int[] i, int iOff, byte[] b, int bOff, int bLen, boolean bigEndian) {
        int bEnd = bOff + bLen;
        for (int j = bOff, k = iOff; j < bEnd; j += 4, k++) {
            i[k] = toInt(b, j, bigEndian);
        }
    }
}

Related

  1. toFloat(byte[] arr)
  2. toFloat(byte[] b)
  3. toFloat(byte[] b)
  4. toFloat(byte[] byteArray)
  5. toFloat(byte[] bytes)
  6. toFloat(byte[] bytes)
  7. toFloat(byte[] bytes)