UnsignedNumberUtil { public static int getUnsignedShort(ByteBuffer byteBuffer) { return Short.toUnsignedInt(byteBuffer.getShort()); } private  UnsignedNumberUtil(); static short getUnsignedByte(byte value); static int getUnsignedShort(ByteBuffer byteBuffer); static int getUnsignedShort(byte[] bytes); static long getUnsignedInt(ByteBuffer byteBuffer); static long getUnsignedInt(byte[] bytes); static BigInteger getUnsignedLong(ByteBuffer byteBuffer); static byte[] toBytes(int ushortValue); static byte[] toBytes(long uintValue); static byte[] toBytes(BigInteger unsignedLongValue); static boolean isWithinUnsignedByte(int value); static boolean isWithinUnsignedShort(int value); static boolean isWithinUnsignedInt(long value); static boolean isWithinUnsignedLong(BigInteger value); static final short UNSIGNED_BYTE_MAX; static final int UNSIGNED_SHORT_MAX; static final long UNSIGNED_INT_MAX; static final BigInteger UNSIGNED_LONG_MAX; }
@Test void getUnsignedShort_test1() { byte[] bytes = new byte[4]; bytes[0] = 0x00; bytes[1] = 0x01; int result = UnsignedNumberUtil.getUnsignedShort(ByteBuffer.wrap(bytes)); assertThat(result).isEqualTo(1); }
@Test void getUnsignedShort_test2() { byte[] bytes = new byte[4]; bytes[0] = (byte) 0xFF; bytes[1] = (byte) 0xFF; int result = UnsignedNumberUtil.getUnsignedShort(ByteBuffer.wrap(bytes)); assertThat(result).isEqualTo(0x0000FFFF); }
@Test void getUnsignedShort_test3() { byte[] bytes = new byte[2]; bytes[0] = 0x00; bytes[1] = 0x01; int result = UnsignedNumberUtil.getUnsignedShort(bytes); assertThat(result).isEqualTo(1); }
@Test void getUnsignedShort_test4() { byte[] bytes = new byte[4]; assertThrows(IllegalArgumentException.class, () -> UnsignedNumberUtil.getUnsignedShort(bytes) ); }