Created
February 4, 2019 22:02
-
-
Save vietj/93e23b2666e8bffc56d6ff100f171035 to your computer and use it in GitHub Desktop.
This file contains 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
private static int branchless1(byte c) { | |
// 48 == 11 0000 | |
// 49 == 11 0001 | |
// 50 == 11 0010 | |
// 57 == 11 1001 | |
byte b1 = (byte) ((c & 0b0001_0000) >> 4); | |
byte b2 = (byte) ((c & 0b0010_0000) >> 5); | |
byte b3 = (byte) ((c & 0b0100_0000) >> 6); | |
byte b4 = (byte) ((c & 0b1000_0000) >> 7); | |
byte b5 = (byte) (b1 & b2 & ~b3 & ~b4); | |
byte b6 = (byte) (b5 * 0xF); | |
byte b7 = (byte) (c & b6); | |
// '0' == 48 == 11 0000 | |
// 0001 | |
// 0010 | |
// 0011 | |
// .... | |
// 0111 | |
// 1000 | |
// 1001 | |
return b7; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment