List of utility methods to do Long Number Create
long | toLong(byte[] bytes) Converts a byte array to a long value. return toLong(bytes, 0, SIZEOF_LONG);
|
long | toLong(byte[] bytes) to Long return ((((long) bytes[0] & 0xff) << 56) | (((long) bytes[1] & 0xff) << 48) | (((long) bytes[2] & 0xff) << 40) | (((long) bytes[3] & 0xff) << 32) | (((long) bytes[4] & 0xff) << 24) | (((long) bytes[5] & 0xff) << 16) | (((long) bytes[6] & 0xff) << 8) | (((long) bytes[7] & 0xff) << 0)); |
long | toLong(byte[] bytes) Creates a long of the given byte array. if (bytes.length != 8) throw new IllegalArgumentException("The input byte array for a long must have 8 values"); return ((long) (bytes[0] & 0xff) << 56) | ((long) (bytes[1] & 0xff) << 48) | ((long) (bytes[2] & 0xff) << 40) | ((long) (bytes[3] & 0xff) << 32) | ((long) (bytes[4] & 0xff) << 24) | ((long) (bytes[5] & 0xff) << 16) ... |
long | toLong(byte[] bytes) Converts a byte array to a long value return toLong(bytes, 0);
|
long | toLong(byte[] bytes, boolean bigEndian) Convert a byte array to a long integer. if (bytes.length > 8 || bytes.length < 1) { throw new IllegalArgumentException("Size of byte array must be between 1 and 8."); long result = 0; if (bigEndian) { for (int i = 0; i < bytes.length; i++) { result |= ((long) 0xFF & bytes[bytes.length - 1 - i]) << i * 8; } else { for (int i = 0; i < bytes.length; i++) { result |= ((long) 0xFF & bytes[i]) << i * 8; return result; |
long | toLong(byte[] bytes, int index) Convert the necessary number of bytes starting at the given index to a long. long val = 0; int typeBytes = Long.SIZE / Byte.SIZE; checkBounds(bytes, index, typeBytes); for (int i = 0; i < typeBytes; i++) { int b = bytes[index++]; b = (b < 0) ? b + 256 : b; int shiftBits = Byte.SIZE * (typeBytes - i - 1); val += (b << shiftBits); ... |
long | toLong(byte[] bytes, int index) to Long return (0xffL & (long) bytes[index]) | (0xff00L & ((long) bytes[index + 1] << 8)) | (0xff0000L & ((long) bytes[index + 2] << 16)) | (0xff000000L & ((long) bytes[index + 3] << 24)) | (0xff00000000L & ((long) bytes[index + 4] << 32)) | (0xff0000000000L & ((long) bytes[index + 5] << 40)) | (0xff000000000000L & ((long) bytes[index + 6] << 48)) | (0xff00000000000000L & ((long) bytes[index + 7] << 56)); |
long | toLong(byte[] bytes, int offset) to Long if (offset + SIZEOF_LONG > bytes.length) { throw new RuntimeException("Cannot decode long from the buffer"); long l = 0; for (int i = offset; i < offset + SIZEOF_LONG; i++) { l <<= 8; l ^= bytes[i] & 0xFF; return l; |
long | ToLong(byte[] bytes, int offset) To Long return ((((long) bytes[offset] & 0xff) << 56) | (((long) bytes[offset + 1] & 0xff) << 48) | (((long) bytes[offset + 2] & 0xff) << 40) | (((long) bytes[offset + 3] & 0xff) << 32) | (((long) bytes[offset + 4] & 0xff) << 24) | (((long) bytes[offset + 5] & 0xff) << 16) | (((long) bytes[offset + 6] & 0xff) << 8) | (((long) bytes[offset + 7] & 0xff) << 0)); |
long | toLong(byte[] bytes, int offset) To long. long l = 0; for (int i = offset; i < offset + 8; i++) { l <<= 8; l ^= bytes[i] & 0xFF; return l; |