This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name

hex()

Examples
color c = #ffcc00;
println(c);          // Prints "-13312"
println(hex(c));     // Prints "FFFFCC00"
println(hex(c, 6));  // Prints "FFCC00"

color c = color(255, 204, 0);
println(c);          // Prints "-13312"
println(hex(c));     // Prints "FFFFCC00"
println(hex(c, 6));  // Prints "FFCC00"
Description Converts a byte, char, int, or color to a String containing the equivalent hexadecimal notation. For example, the color value produced by color(0, 102, 153) will convert to the String value "FF006699". This function can help make your geeky debugging sessions much happier.

Note that the maximum number of digits is 8, because an int value can only represent up to 32 bits. Specifying more than 8 digits will not increase the length of the string further.
Syntax
hex(value)
hex(value, digits)
Parameters
value int, char, or byte: the value to convert
digits int: the number of digits (maximum 8)
ReturnsString
Relatedunhex()
binary()
unbinary()
Updated on May 19, 2014 05:30:00pm PDT

Creative Commons License