List of utility methods to do Long to Byte Array Convert
byte[] | long2bytes(long val) longbytes byte[] data = new byte[8]; data[0] = (byte) (val & 0xFF); data[1] = (byte) (val >> 8 & 0xFF); data[2] = (byte) (val >> 16 & 0xFF); data[3] = (byte) (val >> 24 & 0xFF); data[4] = (byte) (val >> 32 & 0xFF); data[5] = (byte) (val >> 40 & 0xFF); data[6] = (byte) (val >> 48 & 0xFF); ... |
byte[] | convertToByteArray(long l) Converts the long to a 4 byte array. byte[] b = new byte[4]; b[0] = (byte) (255 & (l >> 24)); b[1] = (byte) (255 & (l >> 16)); b[2] = (byte) (255 & (l >> 8)); b[3] = (byte) (255 & l); return b; |
byte[] | long2bytes(long num) longbytes byte[] b = new byte[8]; for (int i = 0; i < 8; i++) { b[i] = (byte) (num >>> (56 - i * 8)); return b; |
byte[] | toBytes(long longValue) to Bytes return new byte[] { (byte) (longValue >>> 56), (byte) (longValue >>> 48), (byte) (longValue >>> 40), (byte) (longValue >>> 32), (byte) (longValue >>> 24), (byte) (longValue >>> 16), (byte) (longValue >>> 8), (byte) (longValue & 0xff) }; |
byte[] | ulong2bytes(long value) ulongbytes byte[] resultByte = { (byte) ((value >>> 24) & 0xFFFFFFFF), (byte) ((value >>> 16) & 0x00FFFFFF), (byte) ((value >>> 8) & 0x0000FFFF), (byte) (value & 0x000000FF) }; return resultByte; |
byte[] | longToBytes(long data, int n) Convert 64 bit long to n bytes. byte buf[] = new byte[n]; for (int i = n - 1; i >= 0; i--) { buf[i] = (byte) data; data = data >> 8; return buf; |