Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static float bytes2float(byte[] bytes, int index) {
        if (null == bytes || bytes.length < (4 + index)) {
            throw new RuntimeException("bytes of float error");
        }

        int temp = bytes[index];
        temp &= 0xff;

        temp |= ((long) bytes[index + 1] << 8);
        temp &= 0xffff;

        temp |= ((long) bytes[index + 2] << 16);
        temp &= 0xffffff;

        temp |= ((long) bytes[index + 3] << 24);
        return Float.intBitsToFloat(temp);
    }
}