Java Byte Array to Float bytesToFloat(byte[] bytes, int startIndex)

Here you can find the source of bytesToFloat(byte[] bytes, int startIndex)

Description

Given a byte array, restore it as an int

License

Open Source License

Parameter

Parameter Description
bytes the byte array
startIndex the starting index of the place the int is stored

Declaration

public static float bytesToFloat(byte[] bytes, int startIndex) 

Method Source Code

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

public class Main {
    /**//from w w  w.j  a  v a  2s.  c  o  m
     * Given a byte array, restore it as an int
     * 
     * @param bytes
     *            the byte array
     * @param startIndex
     *            the starting index of the place the int is stored
     */
    public static float bytesToFloat(byte[] bytes, int startIndex) {
        return (Float.intBitsToFloat(bytesToInt(bytes, startIndex)));
    }

    /**
     * Given a byte array, restore it as an int
     * 
     * @param bytes
     *            the byte array
     * @param startIndex
     *            the starting index of the place the int is stored
     */
    public static int bytesToInt(byte[] bytes, int startIndex) {
        return (((int) bytes[startIndex] & 0xff) | (((int) bytes[startIndex + 1] & 0xff) << 8)
                | (((int) bytes[startIndex + 2] & 0xff) << 16) | (((int) bytes[startIndex + 3] & 0xff) << 24));
    }
}

Related

  1. bytes2float(byte[] bytes)
  2. bytesToFloat(byte[] b)
  3. bytesToFloat(byte[] b, int offset)
  4. bytesToFloat(byte[] bytes)
  5. bytesToFloat(byte[] bytes, int beg)
  6. byteToFloat(byte[] b)
  7. byteToFloat(byte[] b)