hex() test

This is a test of hex(value, digits)

hex() converts a byte, char, int, or color to a String containing the equivalent hexadecimal notation. For example color(0, 102, 153, 255) will convert to the String "FF006699".


Test written by Daniel Hodgin

Source Code:

// 	Hex example
size(500,220, P3D);
background(20);
stroke(128, 128, 128);
fill(64);
rect(1, 1, width-3, height-3);

byte b1 = 23;
byte b2 = 127;
byte b3 = -127;
byte b4 = -127;

char c1 = 'A';
char c2 = '#';
char c3 = '9';
char c4 = 'Z';

int i1 = 255;
int i2 = -65535;
int i3 = 65536;
int i4 = 429844428;

color cl1 = color(255,0,0,0);
color cl2 = #ffcc00;
color cl3 = color(34,255,204,153);
color cl4 = color(0,102,153,255);

PFont font;
font = loadFont("Arial"); 
textFont(font, 14);
fill(32, 255, 0);
text("Bytes", 5, 20);
text("Chars", 5, 120);
text("Ints", 195, 20);
text("Colors", 195, 120);
fill(255, 255, 255);
text("b1: " + b1, 15, 40);
text("hex: " + hex(b1), 80, 40);
text("b2: " + b2, 15, 60);
text("hex: " + hex(b2), 80, 60);
text("b3: " + b3, 15, 80);
text("hex: " + hex(b3), 80, 80);
text("b4: " + b4, 15, 100);
text("hex: " + hex(b4,2), 80, 100);
text("c1: " + c1, 15, 140);
text("hex: " + hex(c1), 80, 140);
text("c2: " + c2, 15, 160);
text("hex: " + hex(c2), 80, 160);
text("c3: " + c3, 15, 180);
text("hex: " + hex(c3), 80, 180);
text("c4: " + c4, 15, 200);
text("hex: " + hex(c4,4), 80, 200);
text("i1: " + i1, 200, 40);
text("hex: " + hex(i1), 370, 40);
text("i2: " + i2, 200, 60);
text("hex: " + hex(i2), 370, 60);
text("i3: " + i3, 200, 80);
text("hex: " + hex(i3), 370, 80);
text("i4: " + i4, 200, 100);
text("hex: " + hex(i4), 370, 100);
text("cl1: " + cl1, 200, 140);
text("hex: " + hex(cl1), 370, 140);
text("cl2: " + cl2, 200, 160);
text("hex: " + hex(cl2), 370, 160);
text("cl3: " + cl3, 200, 180);
text("hex: " + hex(cl3), 370, 180);
text("cl4: " + cl4, 200, 200);
text("hex: " + hex(cl4), 370, 200);