Skip to content

Instantly share code, notes, and snippets.

@CremboC
Created February 11, 2020 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CremboC/02e8a83e94bc9489830dfac333b8fdec to your computer and use it in GitHub Desktop.
Save CremboC/02e8a83e94bc9489830dfac333b8fdec to your computer and use it in GitHub Desktop.
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