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(boolean flag)
This method is equivalent to flag ?
return flag ? 1 : -1;
inttoInt(boolean value)
Convert a boolean value to the appropriate int.
return value ? 1 : 0;
inttoInt(boolean[] bits)
to Int
int value = 0;
for (int i = 0; i < bits.length; i++) {
    boolean isSet = bits[i];
    if (isSet) {
        value += 1 << bits.length - i - 1;
return value;
...
inttoInt(byte b)
to Int
return (int) b >= 0 ? b : (int) b + (int) Math.pow(2, 8);
inttoInt(byte b1, byte b2, byte b3, byte b4)
to Int
return (b1 & 0xFF) | ((b2 & 0xFF) << 8) | ((b3 & 0xFF) << 16) | ((b4 & 0xFF) << 24);
inttoInt(byte byte0, byte byte1, byte byte2, byte byte3)
Constructs int given four bytes.
int b0 = byte3 << 24;
int b1 = (byte2 << 24) >>> 8;
int b2 = (byte1 << 24) >>> 16;
int b3 = (byte0 << 24) >>> 24;
return (b0 | b1 | b2 | b3);
inttoInt(byte byte3, byte byte2, byte byte1, byte byte0)
Convert 4 bytes into an int.
return toInt(toShort(byte3, byte2), toShort(byte1, byte0));
inttoInt(byte in0, byte in1, byte in2, byte in3)
to Int
return (in0 & 0xFF) | ((in1 & 0xFF) << 8) | ((in2 & 0xFF) << 16) | ((in3 & 0xFF) << 24);
inttoInt(byte mostSignificant, byte leastSignificant)
Converts a pair of bytes to a int
int n = 0;
n ^= mostSignificant & 0xFF;
n <<= 8;
n ^= leastSignificant & 0xFF;
return n;
inttoInt(byte src)
to Int
return (int) (src & 0xFF);