Here you can find the source of bytesToInt32(byte[] buffer, int byteOffset, boolean bigEndian)
byteOffset
in buffer
to a signed 32bit integer sample.
public static int bytesToInt32(byte[] buffer, int byteOffset, boolean bigEndian)
//package com.java2s; public class Main { /**//from ww w . j a v a 2s . c o m * Converts a 4 successive bytes starting at <code>byteOffset</code> in * <code>buffer</code> to a signed 32bit integer sample. * <p> * For little endian, buffer[byteOffset] is interpreted as lowest byte, * whereas it is interpreted as highest byte in big endian. * <p> This is a reference function. */ public static int bytesToInt32(byte[] buffer, int byteOffset, boolean bigEndian) { return bigEndian ? ((buffer[byteOffset] << 24) // let Java handle sign-bit | ((buffer[byteOffset + 1] & 0xFF) << 16) // inhibit sign-bit handling | ((buffer[byteOffset + 2] & 0xFF) << 8) // inhibit sign-bit handling | (buffer[byteOffset + 3] & 0xFF)) : ((buffer[byteOffset + 3] << 24) // let Java handle sign-bit | ((buffer[byteOffset + 2] & 0xFF) << 16) // inhibit sign-bit handling | ((buffer[byteOffset + 1] & 0xFF) << 8) // inhibit sign-bit handling | (buffer[byteOffset] & 0xFF)); } }