Skip to content

Instantly share code, notes, and snippets.

@wsky
Last active December 16, 2015 07:59
Show Gist options
  • Save wsky/5402836 to your computer and use it in GitHub Desktop.
Save wsky/5402836 to your computer and use it in GitHub Desktop.
usually bytes parse code, big/little edian
//c# byte 0-255
//java byte -128 to 127
short len = ((chunkData.get()&0xFF)<<8) | (chunkData.get()&0xFF);
//can support .net(c#) usignedbyte
ByteBuffer buffer = ByteBuffer.wrap(new byte[] { (byte) 160, (byte) 134, 1, 0 });
buffer.order(ByteOrder.LITTLE_ENDIAN);
assertEquals(100000, buffer.getInt());
buffer = ByteBuffer.wrap(new byte[] { -96, -122, 1, 0 });
buffer.order(ByteOrder.LITTLE_ENDIAN);
assertEquals(100000, buffer.getInt());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment