Java Byte Array to Int bytes2int(byte[] in, int index1, int index2, int index3)

Here you can find the source of bytes2int(byte[] in, int index1, int index2, int index3)

Description

bytesint

License

BSD License

Declaration

public static int[] bytes2int(byte[] in, int index1, int index2, int index3) 

Method Source Code

//package com.java2s;
/*//from www .j  a  v  a2  s  .  c  o m
 * Copyright 2013, Morten Nobel-Joergensen
 *
 * License: The BSD 3-Clause License
 * http://opensource.org/licenses/BSD-3-Clause
 */

public class Main {
    public static int[] bytes2int(byte[] in, int index1, int index2, int index3) {
        int[] out = new int[in.length / 3];
        for (int i = 0; i < out.length; i++) {
            int index = i * 3;
            int b1 = (in[index + index1] & 0xff) << 16;
            int b2 = (in[index + index2] & 0xff) << 8;
            int b3 = in[index + index3] & 0xff;
            out[i] = b1 | b2 | b3;
        }
        return out;
    }

    public static int[] bytes2int(byte[] in, int index1, int index2, int index3, int index4) {
        int[] out = new int[in.length / 4];
        for (int i = 0; i < out.length; i++) {
            int index = i * 4;
            int b1 = (in[index + index1] & 0xff) << 24;
            int b2 = (in[index + index2] & 0xff) << 16;
            int b3 = (in[index + index3] & 0xff) << 8;
            int b4 = in[index + index4] & 0xff;
            out[i] = b1 | b2 | b3 | b4;
        }
        return out;
    }
}

Related

  1. bytes2int(byte[] bytes)
  2. bytes2int(byte[] bytes, int begin)
  3. bytes2Int(byte[] bytes, int defaultValue)
  4. bytes2Int(byte[] bytes, int offset)
  5. bytes2int(byte[] bytes, int offset, boolean bigEndian)
  6. bytes2int(byte[] src)
  7. bytes2Int(byte[] src, int start)
  8. Bytes2Int16(byte[] sour, int offset)
  9. Bytes2Int32(byte[] sour, int offset)