Skip to content

Instantly share code, notes, and snippets.

@rjlutz
Last active May 22, 2018 16:52
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 rjlutz/24e2b688287c3ebd96f426098cb469d1 to your computer and use it in GitHub Desktop.
Save rjlutz/24e2b688287c3ebd96f426098cb469d1 to your computer and use it in GitHub Desktop.
Assets for Grizzly Gray (Grizzly Grayscale Picker)
private String decToBase(int d, int base) {
// credit to and adapted from:
// https://stackoverflow.com/questions/13465098/decimal-to-hexadecimal-converter-in-java
// Note that there are several one-liners that can be used too
String digits = "0123456789ABCDEF";
String hex = "";
if (d <= 0) hex = "0";
while (d > 0) {
int digit = d % base; // rightmost digit
hex = digits.charAt(digit) + hex; // string concatenation
d = d / base;
}
hex = (hex.length()<2) ? "0" + hex : hex;
return hex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment