Android Byte Array to Float Convert toFloatEx(byte[] b, int pos)

Here you can find the source of toFloatEx(byte[] b, int pos)

Description

to Float Ex

Declaration

public static float toFloatEx(byte[] b, int pos) 

Method Source Code

//package com.java2s;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;

public class Main {
    public static float toFloatEx(byte[] b, int pos) {
        try {//  w  w w  . ja  va 2 s  .  c om
            byte[] byteTmp = new byte[4];
            for (int i = 0; i < 4; i++) {
                byteTmp[i] = b[pos + i];
            }
            ByteBuffer bb = ByteBuffer.wrap(byteTmp);

            FloatBuffer fb = bb.asFloatBuffer();

            return fb.get();
        } catch (Exception e) {
            e.printStackTrace();
            return 0.0f;
        }

    }
}

Related

  1. getFloat(byte[] bytes)
  2. getFloat(int offset, byte[] fromBytes)
  3. getFloats(float[] toFloats, byte[] fromBytes)
  4. getFloats(float[] toFloats, int offset, byte[] fromBytes)
  5. toFloat(byte[] b, int pos)