List of utility methods to do Byte Array to Int Convert
int | toInteger(byte[] input, int offset) to Integer assert offset + 4 <= input.length : "Invalid length " + input.length; return ((input[offset++] & 0xff) << 24) | ((input[offset++] & 0xff) << 16) | ((input[offset++] & 0xff) << 8) | ((input[offset++] & 0xff)); |
int | readInt(byte[] buff, int pos) read Int return (buff[pos++] << 24) + ((buff[pos++] & 0xff) << 16)
+ ((buff[pos++] & 0xff) << 8) + (buff[pos] & 0xff);
|
int | getShort(byte[] data) get Short return (int) ((data[0] << 8) | data[1] & 0xFF); |
int | getUnsignedSafe(byte[] buffer, int pos) Convert byte from byte buffer to unsigned integer. if (null == buffer || pos >= buffer.length || pos < 0) { return 0; int res = toUnsignedInteger(buffer[pos]); return res; |
int | toUInt16(byte[] bytes, int start) to U Int return (bytes[start] & 0xff) + ((bytes[start + 1] & 0xff) << 8);
|
void | intToOctet(byte[] buf, int i) int To Octet buf[0] = (byte) (i >>> 24); buf[1] = (byte) (i >>> 16); buf[2] = (byte) (i >>> 8); buf[3] = (byte) i; |
int | readInt(byte[] byteArray, int offset) read Int int i = 0; for (int j = 0; j < 4; j++) { int shift = 24 - j * 8; i += (byteArray[offset + j] & 0xFF) << shift; return i; |
void | writeInt(byte[] byteArray, int offset, int i) write Int for (int j = 0; j < 4; j++) { int shift = 24 - j * 8; byteArray[offset + j] = (byte) (i >>> shift); |