Java Byte Array to Int bytes2Int(byte[] bytes, int offset)

Here you can find the source of bytes2Int(byte[] bytes, int offset)

Description

bytes Int

License

Open Source License

Declaration

public static int bytes2Int(byte[] bytes, int offset) throws Exception 

Method Source Code

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

public class Main {
    public static int bytes2Int(byte[] bytes, int offset) throws Exception {
        if (bytes == null || bytes.length - offset < 4)
            throw new Exception("bytes==null||bytes.length-offset<4");

        int value = 0;
        for (int i = 0; i < 4; i++) {
            int shift = (i) * 8;
            value += (bytes[i + offset] & 0x000000FF) << shift;
        }//from   w  w w  .j  ava 2 s.co m

        return value;
    }

    public static int bytes2Int(byte[] bytes) throws Exception {
        return bytes2Int(bytes, 0);
    }
}

Related

  1. bytes2int(byte[] bytes)
  2. bytes2int(byte[] bytes)
  3. bytes2int(byte[] bytes)
  4. bytes2int(byte[] bytes, int begin)
  5. bytes2Int(byte[] bytes, int defaultValue)
  6. bytes2int(byte[] bytes, int offset, boolean bigEndian)
  7. bytes2int(byte[] in, int index1, int index2, int index3)
  8. bytes2int(byte[] src)
  9. bytes2Int(byte[] src, int start)