Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Created March 3, 2013 12:28
Show Gist options
  • Save thomwiggers/5075926 to your computer and use it in GitHub Desktop.
Save thomwiggers/5075926 to your computer and use it in GitHub Desktop.
/**
* Maakt gebruik van het feit dat shorts 16bit zijn
*
*
* @param left
* @param right
* @return a size 3 byte array containing, when concatenated, (left << 12) |
* right
*/
public static Byte[] compressBytes(final short left, final short right){
if(((left >> 12) != 0) || ((right >> 12) != 0))
throw new IllegalArgumentException("input size too large");
final int dinges = (left << 12) | right;
final byte b1 = (byte) (dinges >> 16);
final byte b2 = (byte) ((dinges << 8) >> 8);
final byte b3 = (byte) ((dinges << 16) >> 16);
return new Byte[] {b1, b2, b3};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment