Java Utililty Methods Byte Array to Int

List of utility methods to do Byte Array to Int

Description

The list of methods to do Byte Array to Int are organized into topic(s).

Method

intbytes2int(byte[] bytes)
bytesint
int targets = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00) | ((bytes[2] << 24) >>> 8) | (bytes[3] << 24);
return targets;
intbytes2int(byte[] bytes, int begin)
convert a 4byte-array to an integer big-endian alignment
int value = 0;
int mask = 0x000000FF;
for (int i = 0; i < 4; i++) {
    value <<= 8;
    value |= mask & bytes[begin + i];
return value;
intbytes2Int(byte[] bytes, int defaultValue)
bytes Int
if (bytes == null) {
    return defaultValue;
} else {
    return bytes2Int(bytes);
intbytes2Int(byte[] bytes, int offset)
bytes Int
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;
return value;
...
intbytes2int(byte[] bytes, int offset, boolean bigEndian)
bytesint
int val = 0;
if (bigEndian) {
    val += (bytes[offset + 0] & 0xff) << 24;
    val += (bytes[offset + 1] & 0xff) << 16;
    val += (bytes[offset + 2] & 0xff) << 8;
    val += (bytes[offset + 3] & 0xff);
} else {
    val += (bytes[offset + 3] & 0xff) << 24;
...
int[]bytes2int(byte[] in, int index1, int index2, int index3)
bytesint
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;
intbytes2int(byte[] src)
bytesint
return bytes2int(src, 0, src.length);
intbytes2Int(byte[] src, int start)
bytes Int
int a = src[start];
int b = src[start + 1];
int c = src[start + 2];
int d = src[start + 3];
return (d << 24) | (c << 16) | (b << 8) | a;
intBytes2Int16(byte[] sour, int offset)
Bytes Int
int ret = Bytes2Uint16(sour, offset);
return ((ret & 0x8000) == 0x8000) ? 0xFFFF0000 | ret : ret;
intBytes2Int32(byte[] sour, int offset)
Bytes Int
return (((sour[offset] << 24) & 0xFF000000) | ((sour[offset + 1] << 16) & 0x00FF0000)
        | ((sour[offset + 2] << 8) & 0x0000FF00) | (sour[offset + 3] & 0x000000FF));