Java Byte Array to Int bytes2int(byte[] bytes, int begin)

Here you can find the source of bytes2int(byte[] bytes, int begin)

Description

convert a 4byte-array to an integer big-endian alignment

License

Open Source License

Parameter

Parameter Description
bytes a parameter
begin the starting index of the integer

Declaration

public static int bytes2int(byte[] bytes, int begin) 

Method Source Code

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

public class Main {
    /**/* w  w  w .j a v a2s  .  co  m*/
     * convert a 4byte-array to an integer
     * big-endian alignment
     * @param bytes 
     * @param begin the starting index of the integer
     */
    public static int bytes2int(byte[] bytes, int begin) {
        int value = 0;
        int mask = 0x000000FF;
        for (int i = 0; i < 4; i++) {
            value <<= 8;
            value |= mask & bytes[begin + i];
            //@debug
            //System.out.printf("i=%d: val: %08X\n",i,value);
        }
        return value;
    }
}

Related

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