Created
February 11, 2020 09:09
-
-
Save CremboC/02e8a83e94bc9489830dfac333b8fdec 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
public class BaseConversion { | |
private static final char[] HEXES = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; | |
public static String getHex(long value) { | |
final StringBuilder hex = new StringBuilder(16); | |
byte[] result = new byte[8]; | |
for (int i = 7; i >= 0; i--) { | |
result[i] = (byte) (value & 0xffL); | |
value >>= 8; | |
} | |
for (final byte b : result) { | |
char c1 = HEXES[(b & 0xF0) >> 4]; | |
char c2 = HEXES[(b & 0x0F)]; | |
hex | |
.append(c1) | |
.append(c2); | |
} | |
return hex.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment