Convert byte array to long in Java
Description
The following code shows how to convert byte array to long.
Example
// www . j a va 2 s .c o m
import java.nio.ByteBuffer;
public class Main {
public static long convertToLong(byte[] array) {
ByteBuffer buffer = ByteBuffer.wrap(array);
return buffer.getLong();
}
public static void main(String[] argv) {
System.out.println(convertToLong(new byte[]{1,2,3,4,5,6,7,8,9,8,67}));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »