Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static int bytesToInt(byte[] values) {
        if (values == null || values.length == 0 || values.length > 4) {
            throw new RuntimeException("valid byte array");
        }

        int ret = 0;
        int len = values.length - 1;
        for (int i = 0; i < len; ++i) {
            ret |= (values[i] & 0xff);
            ret <<= 8;
        }
        ret |= (values[len] & 0xff);

        return ret;
    }
}