List of utility methods to do Byte Array to Long Convert
long | byteToLong(byte[] b) byte To Long if (b.length != 8) { return -1; return ((((long) b[0] & 0xff) << 56) | (((long) b[1] & 0xff) << 48) | (((long) b[2] & 0xff) << 40) | (((long) b[3] & 0xff) << 32) | (((long) b[4] & 0xff) << 24) | (((long) b[5] & 0xff) << 16) ... |
long | bytesLE2long(byte[] b, int off) bytes L Elong return ((b[off + 7] & 0xffL) << 56) | ((b[off + 6] & 0xffL) << 48)
| ((b[off + 5] & 0xffL) << 40)
| ((b[off + 4] & 0xffL) << 32)
| ((b[off + 3] & 0xffL) << 24)
| ((b[off + 2] & 0xffL) << 16)
| ((b[off + 1] & 0xffL) << 8) | (b[off] & 0xffL);
|
long[] | bytesLE2longs(byte[] b) bytes L Elongs if (b == null) return null; if ((b.length & 0x7) != 0) throw new IllegalArgumentException("byte[" + b.length + "]"); long[] val = new long[b.length >> 3]; for (int i = 0; i < val.length; i++) val[i] = bytesLE2long(b, i << 3); return val; ... |
long | bytesToLong(byte[] bytes) Converts a byte[] of unsigned bytes in big-endian order to a long. long l = 0;
l |= (bytes[0] & 0xFFL) << 56;
l |= (bytes[1] & 0xFFL) << 48;
l |= (bytes[2] & 0xFFL) << 40;
l |= (bytes[3] & 0xFFL) << 32;
l |= (bytes[4] & 0xFFL) << 24;
l |= (bytes[5] & 0xFFL) << 16;
l |= (bytes[6] & 0xFFL) << 8;
...
|
long | bytesToLong(byte[] bytes) bytes To Long if (bytes == null) { return 0l; if (bytes.length < 8) { byte[] mask = new byte[(8 - bytes.length)]; bytes = append(mask, bytes); buffer.clear(); ... |
long | bytesToLong(byte[] bytes, int start) bytes To Long LONG_BUFFER.position(0);
LONG_BUFFER.put(bytes, start, LONG_BYTES);
LONG_BUFFER.flip();
return LONG_BUFFER.getLong(0);
|
long | bytes2ulong(byte[] bytes, int from, int to) bytesulong long result = 0; int len = to - from; for (int i = from; i < to; i++) { int shiftValue = (to - i - 1) * 8; result += (bytes[i] << shiftValue) & (0xFFFFFFFF >>> ((len - 1) * 8 - shiftValue)); return result; ... |
long | getLong(byte[] bb, int index) get Long return ((((long) bb[index + 0] & 0xff) << 56) | (((long) bb[index + 1] & 0xff) << 48) | (((long) bb[index + 2] & 0xff) << 40) | (((long) bb[index + 3] & 0xff) << 32) | (((long) bb[index + 4] & 0xff) << 24) | (((long) bb[index + 5] & 0xff) << 16) | (((long) bb[index + 6] & 0xff) << 8) | (((long) bb[index + 7] & 0xff) << 0)); |
long | getLong(byte[] bb, int index) get Long return ((((long) bb[index + 7] & 0xff) << 56) | (((long) bb[index + 6] & 0xff) << 48) | (((long) bb[index + 5] & 0xff) << 40) | (((long) bb[index + 4] & 0xff) << 32) | (((long) bb[index + 3] & 0xff) << 24) | (((long) bb[index + 2] & 0xff) << 16) | (((long) bb[index + 1] & 0xff) << 8) | (((long) bb[index + 0] & 0xff) << 0)); |
long | getLong(byte[] buf, boolean bigEndian) Convert byte sequence into java long from first 8 bytes return getLong(buf, 0, bigEndian);
|