List of usage examples for java.lang Integer SIZE
int SIZE
To view the source code for java.lang Integer SIZE.
Click Source Link
From source file:Main.java
public static void main(String[] args) { System.out.println(Integer.SIZE); }
From source file:Main.java
public static void main(String[] arg) { System.out.println(Integer.SIZE); }
From source file:Main.java
protected static byte[] getBytes(int i) { return ByteBuffer.allocate(Integer.SIZE / 8).putInt(i).array(); }
From source file:Main.java
public static byte[] intToByteArray(int value) { ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putInt(value);/*w ww . j a va 2s . c o m*/ return buffer.array(); }
From source file:Main.java
public static byte[] intToByteArrayLE(int value) { ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(value);/*w w w. j av a2 s . com*/ return buffer.array(); }
From source file:Main.java
public static int byteArrayToInt(byte[] bytes) throws IllegalArgumentException { if (bytes.length != (Integer.SIZE / Byte.SIZE)) { throw new IllegalArgumentException("Incorrect array size to convert to an int"); }//from ww w.j a v a2 s . co m ByteBuffer buffer = ByteBuffer.wrap(bytes); buffer.order(ByteOrder.BIG_ENDIAN); return buffer.getInt(); }
From source file:Main.java
public static int byteArrayToIntLE(byte[] bytes) throws IllegalArgumentException { if (bytes.length != (Integer.SIZE / Byte.SIZE)) { throw new IllegalArgumentException("Incorrect array size to convert to an int"); }//from w w w.j a v a2 s . c o m ByteBuffer buffer = ByteBuffer.wrap(bytes); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.getInt(); }
From source file:Main.java
/** * Convert a one or two byte array of bytes to an unsigned two-byte integer. * //from w w w . j av a 2 s . co m * <p><b>NOTE:</b> This function mostly exists as an example of how to use * twoBytesToUnsignedInt(). It is unlikely the use case it embodies * will occur often.</p> * * @param ba * @return */ public static int byteArrayToUnsignedInt(byte[] byteArray) { if (byteArray.length > Integer.SIZE) throw new IllegalArgumentException("Array length must match one of the following types:\n Byte==" + Byte.SIZE + ", Short==" + Short.SIZE + ", Integer==" + Integer.SIZE); return (int) byteArrayToUnsignedLong(byteArray); }
From source file:Main.java
/** * Calculates the integer at the position <code>offset</code> in the buffer * @param buffer the offset of the integer * @param offset the buffer holding the integer. * * @return the calculated integer/*from w ww .j ava 2s. c om*/ */ public static int intFromBuffer(byte[] buffer, int offset) { int result = 0; for (int i = 0; i < Integer.SIZE / Byte.SIZE; i++) { result <<= Byte.SIZE; result |= (buffer[offset + i] & 0xFF); } return result; }
From source file:Main.java
/**buffer methods*/ public static IntBuffer makeIntBuffer(int[] array) { final int integerSize = Integer.SIZE / 8; ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * integerSize); byteBuffer.order(ByteOrder.nativeOrder()); IntBuffer intBuffer = byteBuffer.asIntBuffer(); intBuffer.put(array);/*from w ww. ja v a 2 s. c o m*/ intBuffer.position(0); return intBuffer; }