-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRGBtoHEX.java
More file actions
38 lines (34 loc) · 756 Bytes
/
RGBtoHEX.java
File metadata and controls
38 lines (34 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package algorithms;
/**
* Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string.
*
* @author joeytawadrous
*/
public class RGBtoHEX
{
public static void main (String[] args)
{
System.out.println(formatRGB(3,3,3));
}
/**
* Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string.
* @param r
* @param g
* @param b
* @return Hex numbers
*/
public static String formatRGB(int r, int g, int b)
{
return(toHex(r) + toHex(g) + toHex(b)).toUpperCase();
}
/**
* Converts int number to Hex.
* @param c
* @return hex number
*/
public static String toHex(int c)
{
String s = Integer.toHexString(c);
return(s.length() == 1) ? "0" + s : s;
}
}