Convert byte array to int in Java
Description
The following code shows how to convert byte array to int.
Example
// ww w . ja v a 2s . c om
import java.nio.ByteBuffer;
public class Main {
public static int convertToInt(byte[] array) {
ByteBuffer buffer = ByteBuffer.wrap(array);
return buffer.getInt();
}
public static void main(String[] argv) {
System.out.println(convertToInt(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 »