Created
March 3, 2013 12:28
-
-
Save thomwiggers/5075926 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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