Java Utililty Methods Integer Create

List of utility methods to do Integer Create

Description

The list of methods to do Integer Create are organized into topic(s).

Method

inttoInt(byte[] b)
to Int
int s = 0;
int s0 = b[0] & 0xff;
int s1 = b[1] & 0xff;
int s2 = b[2] & 0xff;
int s3 = b[3] & 0xff;
s3 <<= 24;
s2 <<= 16;
s1 <<= 8;
...
inttoInt(byte[] b)
to Int
if (b.length > 4)
    throw new NumberFormatException("int has only 4 bytes");
int i = 0;
for (byte x : b) {
    i <<= 8;
    i |= (x & 0xFF);
return i;
...
inttoInt(byte[] b)
to Int
return (((((int) b[3]) & 0xFF) << 32) + ((((int) b[2]) & 0xFF) << 40) + ((((int) b[1]) & 0xFF) << 48)
        + ((((int) b[0]) & 0xFF) << 56));
inttoInt(byte[] b, int begin_index, int len)
to Int
byte[] a = subset(b, begin_index, len);
int n = 0;
if (a == null || a.length == 0)
    return n;
for (int i = 0; i < a.length; i++) {
    n += ((a[i] & 0xff) << ((a.length - i - 1) * 8));
return n;
...
inttoInt(byte[] block, int pos, int len)
to Int
try {
    return Integer.parseInt(new String(block, pos, len));
} catch (Exception ex) {
    return 0;
inttoInt(byte[] bRefArr)
to Int
int iOutcome = 0;
byte bLoop;
for (int i = 0, len = bRefArr.length; i < len; i++) {
    bLoop = bRefArr[i];
    iOutcome += (bLoop & 0xFF) << (8 * (len - 1 - i));
return iOutcome;
inttoInt(byte[] buf)
to Int
int ch1 = buf[0] & 0xff;
int ch2 = buf[1] & 0xff;
int ch3 = buf[2] & 0xff;
int ch4 = buf[3] & 0xff;
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
inttoInt(byte[] buf)
to Int
int n = 0;
for (byte b : buf) {
    n = (n << 8) + (b & 0xff);
return n;
inttoInt(byte[] buf, int off)
Converts 4 bytes to an int at the specified offset in the given byte array.
int lg = (buf[off] & 0xff) << 24;
lg |= (buf[off + 1] & 0xff) << 16;
lg |= (buf[off + 2] & 0xff) << 8;
lg |= (buf[off + 3] & 0xff);
return lg;
inttoInt(byte[] buf, int pos)
to Int
return toUnsignedByte(buf, pos) << 24 + toUnsignedByte(buf, pos + 1) << 16
        + toUnsignedByte(buf, pos + 2) << 8 + toUnsignedByte(buf, pos + 3);