Pages: [1]   Go Down
Author Topic: Hex Color Value to RGB array help  (Read 5368 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 96
Why is it so?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hey all
i have search long and hard for a quick solution to a hex to array convertor,
strol() just hasen't provided the intended result, or maybe i am doing it wrong.

what i need is an array representation of a converted hex number:

pseudo

hexToArray(hex)
{
   ...
   return array;
}

array = hexToArray("FFFFFF"); // this should yeild (255,255,255);
Logged

Essex, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 150
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

strtol is a good way of converting the string to an efficient packed 24 bit container for the RGB values that you need. You could then add some convenience #defines to get at the components of the value returned by strtol:

#define RED(a) (a>>16)
#define GREEN(a) ((a>>smiley-cool & 0xff)
#define BLUE(a) (a & 0xff)

Don't forget that the 'base' parameter to strtol is 16.
« Last Edit: January 20, 2011, 04:09:58 pm by foxbat » Logged

Home of the Nokia QVGA TFT LCD hacks: http://andybrown.me.uk

Pages: [1]   Go Up
Jump to: