@Test public void testBytes2int() throws Exception { assertEquals(0, ArraysUtil.bytes2int(null)); assertEquals(960488, ArraysUtil.bytes2int(new byte[] {0, 14, -89, -24})); assertEquals(127, ArraysUtil.bytes2int(new byte[] {0, 0, 0, 127})); assertEquals(2560488, ArraysUtil.bytes2int(new byte[] {0, 39, 17, -24})); }
public static int bytes2int(byte[] bytes) { if (bytes == null) { return 0; } switch (bytes.length) { case 1: return bytes[0] & 0xFF; case 2: return (bytes[0] & 0xFF) << 8 | bytes[1] & 0xFF; case 3: return (bytes[0] & 0xFF) << 16 | (bytes[1] & 0xFF) << 8 | bytes[2] & 0xFF; case 4: return (bytes[0] & 0xFF) << 24 | (bytes[1] & 0xFF) << 16 | (bytes[2] & 0xFF) << 8 | bytes[3] & 0xFF; default: return 0; } }
ArraysUtil { public static int bytes2int(byte[] bytes) { if (bytes == null) { return 0; } switch (bytes.length) { case 1: return bytes[0] & 0xFF; case 2: return (bytes[0] & 0xFF) << 8 | bytes[1] & 0xFF; case 3: return (bytes[0] & 0xFF) << 16 | (bytes[1] & 0xFF) << 8 | bytes[2] & 0xFF; case 4: return (bytes[0] & 0xFF) << 24 | (bytes[1] & 0xFF) << 16 | (bytes[2] & 0xFF) << 8 | bytes[3] & 0xFF; default: return 0; } } }
ArraysUtil { public static int bytes2int(byte[] bytes) { if (bytes == null) { return 0; } switch (bytes.length) { case 1: return bytes[0] & 0xFF; case 2: return (bytes[0] & 0xFF) << 8 | bytes[1] & 0xFF; case 3: return (bytes[0] & 0xFF) << 16 | (bytes[1] & 0xFF) << 8 | bytes[2] & 0xFF; case 4: return (bytes[0] & 0xFF) << 24 | (bytes[1] & 0xFF) << 16 | (bytes[2] & 0xFF) << 8 | bytes[3] & 0xFF; default: return 0; } } private  ArraysUtil(); }
ArraysUtil { public static int bytes2int(byte[] bytes) { if (bytes == null) { return 0; } switch (bytes.length) { case 1: return bytes[0] & 0xFF; case 2: return (bytes[0] & 0xFF) << 8 | bytes[1] & 0xFF; case 3: return (bytes[0] & 0xFF) << 16 | (bytes[1] & 0xFF) << 8 | bytes[2] & 0xFF; case 4: return (bytes[0] & 0xFF) << 24 | (bytes[1] & 0xFF) << 16 | (bytes[2] & 0xFF) << 8 | bytes[3] & 0xFF; default: return 0; } } private  ArraysUtil(); static BitSet getBitAddress(String ip); static int bytes2int(byte[] bytes); static byte[] combine(byte[]... bytes); static byte convertBits(Boolean... bits); static byte[] copy(byte[] source); static int getBit(byte _byte, int position); static byte[] int2bytes(int value); static byte[] int2bytesCropp(int value, int nbytes2cropp); static byte[] readBytes(byte[] source, int start); static byte[] readBytes(byte[] source, int start, int length); static byte reverseBitsByte(byte x); static byte setBit(byte _byte, int position, boolean value); }
ArraysUtil { public static int bytes2int(byte[] bytes) { if (bytes == null) { return 0; } switch (bytes.length) { case 1: return bytes[0] & 0xFF; case 2: return (bytes[0] & 0xFF) << 8 | bytes[1] & 0xFF; case 3: return (bytes[0] & 0xFF) << 16 | (bytes[1] & 0xFF) << 8 | bytes[2] & 0xFF; case 4: return (bytes[0] & 0xFF) << 24 | (bytes[1] & 0xFF) << 16 | (bytes[2] & 0xFF) << 8 | bytes[3] & 0xFF; default: return 0; } } private  ArraysUtil(); static BitSet getBitAddress(String ip); static int bytes2int(byte[] bytes); static byte[] combine(byte[]... bytes); static byte convertBits(Boolean... bits); static byte[] copy(byte[] source); static int getBit(byte _byte, int position); static byte[] int2bytes(int value); static byte[] int2bytesCropp(int value, int nbytes2cropp); static byte[] readBytes(byte[] source, int start); static byte[] readBytes(byte[] source, int start, int length); static byte reverseBitsByte(byte x); static byte setBit(byte _byte, int position, boolean value);  }