List of utility methods to do Long to Byte Array Convert
byte[] | toBytes(long value) to Bytes byte[] dest = new byte[8]; toBytes(value, dest, 0); return dest; |
void | toBytes(long value, byte[] dest, int destPos) to Bytes for (int i = 0; i < 8; i++) { dest[i + destPos] = (byte) (value >> ((7 - i) * 8)); |
void | toByteArray(long val, byte[] b, int pos) to Byte Array assert (pos + 8 <= b.length); for (int i = 0; i < 8; ++i) { b[pos + i] = (byte) (val & 0x00000000000000FFl); val = val >> 8; |
void | toByteArray(long val, int w, byte[] b, int pos) to Byte Array assert (pos + 8 <= b.length); for (int i = 0; i < w; ++i) { b[pos + i] = (byte) (val & 0x00000000000000FFl); val = val >> 8; |
byte[] | getByteArrayByLong(long value, int n) get bytes by the long value. return getByteArrayByLong(value, n, true);
|
byte[] | getByteArrayByLong(long value, int n, boolean isLH) get bytes by the long value byte[] dest = new byte[n]; for (int i = 0; i < n; i++) { dest[i] = (byte) ((value >> ((isLH ? i : n - i - 1) * 8)) & 0xFF); return dest; |
byte[] | getBytes(long data) get Bytes byte[] bytes = new byte[8]; bytes[0] = (byte) (data & 0xff); bytes[1] = (byte) ((data >> 8) & 0xff); bytes[2] = (byte) ((data >> 16) & 0xff); bytes[3] = (byte) ((data >> 24) & 0xff); bytes[4] = (byte) ((data >> 32) & 0xff); bytes[5] = (byte) ((data >> 40) & 0xff); bytes[6] = (byte) ((data >> 48) & 0xff); ... |
void | uint32ToByteArrayLE(long value, byte[] output, int offset) uint To Byte Array LE output[offset + 0] = (byte) (0xFFL & (value >> 0)); output[offset + 1] = (byte) (0xFFL & (value >> 8)); output[offset + 2] = (byte) (0xFFL & (value >> 16)); output[offset + 3] = (byte) (0xFFL & (value >> 24)); |
void | uint64ToByteArrayLE(long value, byte[] output, int offset) uint To Byte Array LE output[offset + 0] = (byte) (0xFFL & (value >> 0)); output[offset + 1] = (byte) (0xFFL & (value >> 8)); output[offset + 2] = (byte) (0xFFL & (value >> 16)); output[offset + 3] = (byte) (0xFFL & (value >> 24)); output[offset + 4] = (byte) (0xFFL & (value >> 32)); output[offset + 5] = (byte) (0xFFL & (value >> 40)); output[offset + 6] = (byte) (0xFFL & (value >> 48)); output[offset + 7] = (byte) (0xFFL & (value >> 56)); ... |
byte[] | long2byteArray(final long number, final int length, final boolean swapHalfWord) Converts a long number to a byte array Halfwords can be swapped by setting swapHalfWord=true. byte[] ret = new byte[length]; int pos = 0; long tmp_number = 0; if (length % 2 != 0 || length < 2) { throw new UnsupportedOperationException(); tmp_number = number; for (pos = length - 1; pos >= 0; pos--) { ... |