NumberUtils { public static BigInteger byteArrayToPositive(final byte[] rawBytes) { if (null == rawBytes || rawBytes.length == 0) { return BigInteger.ZERO; } byte[] canonicalBytes = rawBytes; if ((rawBytes[0] & 0x80) != 0) { canonicalBytes = new byte[rawBytes.length + 1]; canonicalBytes[0] = 0x00; System.arraycopy(rawBytes, 0, canonicalBytes, 1, rawBytes.length); } return new BigInteger(canonicalBytes); }  @SuppressWarnings("unchecked") static T convert(final Number number, final Class<T> targetClass); @SuppressWarnings("unchecked") static T parse(final String text, final Class<?> clazz); static T parse(final String text, final Class<T> targetClass,
      final NumberFormat numberFormat); static byte[] positiveToByteArray(final BigInteger positiveNumber); static BigInteger byteArrayToPositive(final byte[] rawBytes);  }
@Test public void testByteAraryToPostive() { final Object[][] testParameters = new Object[][] { {new byte[0], BigInteger.ZERO}, {new byte[] {(byte) 0x00}, BigInteger.valueOf(0L)}, {new byte[] {(byte) 0x7F}, BigInteger.valueOf(127L)}, {new byte[] {(byte) 0xFF}, BigInteger.valueOf(255L)} }; for (final Object[] testParameter : testParameters) { final byte[] rawBytes = (byte[]) testParameter[0]; final BigInteger expected = (BigInteger) testParameter[1]; final BigInteger actual = NumberUtils.byteArrayToPositive(rawBytes); assertTrue(expected.equals(actual)); } }