Hi all,
I have an array of chars like so:
I have an array of chars like so:
- char[] values = { '0', '0', '0', '0', 'F', 'D', 'D', 'F', 'F', '0', '0', 'F', 'A', '7', '7', 'A' };
I would like to parse it as actual hex values and then integers to pull from another array:
- color[] colors;
- colors = new color[16];
- populateColors();
- for (int i = 0; i < 16; i++){
- fill(colors[unhex(values[i])]);
- rect(i * 16, 0, 16, 16);
- }
Is there a simple way to do this other than manually with a switch function?
Thanks in advance.
- int charToHex(char in){
- switch (in) {
- case '1':
- return 1;
- case '2':
- return 2;
- case '3':
- return 3;
- ...
- case 'E':
- return 14;
- case 'F':
- return 15;
- default:
- return 0;
- }
- }
Thanks in advance.
1