Nov 18

The following code can be used to convert a byte array (containing the bytes of a long) into a long.

	public static long byteArrayToLong(byte[] bytes) {
		long l = 0;
		for (int i=0; i<8; i++) {
			l <<= 8;
			l ^= (long) bytes[i] & 0xff;
		return l;

This is the reverse of “How to convert a long to a byte array“.

written by objects \\ tags: , , , ,

Leave a Reply

You must be logged in to post a comment.