@Test public void bytesToUnsignedInteger() { Assert.assertEquals(0, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x00})); Assert.assertEquals(1, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x01})); Assert.assertEquals(127, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x7f})); Assert.assertEquals(128, ConversionUtils.bytesToUnsignedInteger(new byte[] {(byte) 0x80})); Assert.assertEquals(255, ConversionUtils.bytesToUnsignedInteger(new byte[] {(byte) 0xff})); Assert.assertEquals(0x0000, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x00, 0x00})); Assert.assertEquals(0x0001, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x00, 0x01})); Assert.assertEquals(0x007f, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x00, 0x7f})); Assert.assertEquals(0x0080, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x00, (byte) 0x80})); Assert.assertEquals(0x0100, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x01, 0x00})); Assert.assertEquals(0x0101, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x01, 0x01})); Assert.assertEquals(0x7fff, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x7f, (byte) 0xff})); Assert.assertEquals(0xffff, ConversionUtils.bytesToUnsignedInteger(new byte[] {(byte) 0xff, (byte) 0xff})); Assert.assertEquals(0x11223344, ConversionUtils.bytesToUnsignedInteger(new byte[] {0x11, 0x22, 0x33, 0x44})); Assert.assertEquals(0xffffffffL, ConversionUtils.bytesToUnsignedInteger(new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff})); }
public static long bytesToUnsignedInteger(byte[] data) { final int length = data.length; long value = 0L; for (int i = 0; i < length; i++) { long b = data[i]; if (b < 0) { b += 256; } value |= b << (length - i - 1) * 8; } return value; }
ConversionUtils { public static long bytesToUnsignedInteger(byte[] data) { final int length = data.length; long value = 0L; for (int i = 0; i < length; i++) { long b = data[i]; if (b < 0) { b += 256; } value |= b << (length - i - 1) * 8; } return value; } }
ConversionUtils { public static long bytesToUnsignedInteger(byte[] data) { final int length = data.length; long value = 0L; for (int i = 0; i < length; i++) { long b = data[i]; if (b < 0) { b += 256; } value |= b << (length - i - 1) * 8; } return value; }  }
ConversionUtils { public static long bytesToUnsignedInteger(byte[] data) { final int length = data.length; long value = 0L; for (int i = 0; i < length; i++) { long b = data[i]; if (b < 0) { b += 256; } value |= b << (length - i - 1) * 8; } return value; }  static byte[] integerToBytes(long value, int length); static long bytesToSignedInteger(byte[] data); static byte bytesToI1(byte[] data); static int bytesToI2(byte[] data); static int bytesToI4(byte[] data); static long bytesToI8(byte[] data); static long bytesToUnsignedInteger(byte[] data); }
ConversionUtils { public static long bytesToUnsignedInteger(byte[] data) { final int length = data.length; long value = 0L; for (int i = 0; i < length; i++) { long b = data[i]; if (b < 0) { b += 256; } value |= b << (length - i - 1) * 8; } return value; }  static byte[] integerToBytes(long value, int length); static long bytesToSignedInteger(byte[] data); static byte bytesToI1(byte[] data); static int bytesToI2(byte[] data); static int bytesToI4(byte[] data); static long bytesToI8(byte[] data); static long bytesToUnsignedInteger(byte[] data);  }