Last active
May 22, 2018 16:52
-
-
Save rjlutz/24e2b688287c3ebd96f426098cb469d1 to your computer and use it in GitHub Desktop.
Assets for Grizzly Gray (Grizzly Grayscale Picker)
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 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