Java Byte Array to Float bytesToFloat(byte[] b, int offset)

Here you can find the source of bytesToFloat(byte[] b, int offset)

Description

bytes To Float

License

Apache License

Declaration

public static float bytesToFloat(byte[] b, int offset) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static float bytesToFloat(byte[] b, int offset) {
        int l;/*from  w w  w. jav  a2 s  .  co m*/
        l = b[offset + 0];
        l &= 0xff;
        l |= ((long) b[offset + 1] << 8);
        l &= 0xffff;
        l |= ((long) b[offset + 2] << 16);
        l &= 0xffffff;
        l |= ((long) b[offset + 3] << 24);
        return Float.intBitsToFloat(l);
    }

    public static float bytesToFloat(byte[] bytes) {
        return Float.intBitsToFloat(bytesToInt(bytes));
    }

    public static int bytesToInt(byte[] bytes) {
        return (0xff & bytes[0]) | (0xff00 & (bytes[1] << 8)) | (0xff0000 & (bytes[2] << 16))
                | (0xff000000 & (bytes[3] << 24));
    }

    public static int bytesToInt(byte[] b, int offset) {
        return (0xff & b[offset]) | (0xff00 & (b[offset + 1] << 8)) | (0xff0000 & (b[offset + 2] << 16))
                | (0xff000000 & (b[offset + 3] << 24));
    }
}

Related

  1. bytes2float(byte[] b)
  2. bytes2Float(byte[] b, float defaultValue)
  3. bytes2float(byte[] bytes)
  4. bytes2float(byte[] bytes)
  5. bytesToFloat(byte[] b)
  6. bytesToFloat(byte[] bytes)
  7. bytesToFloat(byte[] bytes, int beg)
  8. bytesToFloat(byte[] bytes, int startIndex)
  9. byteToFloat(byte[] b)