Java Example Program / Sample Source Code
public class IntegerToHtmlRGB {
public static void main(String args[]) {
System.out.println(toHtmlRGB(128));
}
public static String toHtmlRGB(int rgb) {
if (rgb > 0xFFFFFF) {
rgb = 0xFFFFFF;
}
if (rgb < 0) {
rgb = 0;
}
String string = "000000" + Integer.toHexString(rgb);
return "#" + string.substring(string.length() - 6);
}
} |
|
|