UnsignedUtil { public static byte[] encodeInt32(int id) { byte[] bytes = new byte[4]; bytes[0] = (byte)(id&0x000000ff); bytes[1] = (byte)((id&0x0000ff00)>>8); bytes[2] = (byte)((id&0x00ff0000)>>16); bytes[3] = (byte)((id&0xff000000)>>24); return bytes; }  static int read_UAFV1_UINT16(ByteInputStream bytes); static byte[] encodeInt(int id); static byte[] encodeInt32(int id);  }
@Test public void max_int() { int m = Integer.MAX_VALUE; byte[] mBytes = UnsignedUtil.encodeInt32(m); byte[] mBytesBigEndian = reverse (mBytes); BigInteger big = new BigInteger(mBytesBigEndian); assertTrue (big.intValue() == m); }
@Test public void small_int() { int m = 250; byte[] mBytes = UnsignedUtil.encodeInt32(m); byte[] mBytesBigEndian = reverse (mBytes); BigInteger big = new BigInteger(mBytesBigEndian); assertTrue (big.intValue() == m); }
@Test public void fourBytes() { int m = 0x030201ff; byte[] mBytes = UnsignedUtil.encodeInt32(m); byte[] mBytesBigEndian = reverse (mBytes); BigInteger big = new BigInteger(mBytesBigEndian); assertTrue (big.intValue() == m); assertTrue(mBytes[0]==-1); assertTrue(mBytes[1]==0x01); assertTrue(mBytes[2]==0x02); assertTrue(mBytes[3]==0x03); }