Go Down

Topic: Hex Color Value to RGB array help (Read 5 times) previous topic - next topic

32teeth

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);

Andy Brown

#1
Jan 20, 2011, 10:09 pm Last Edit: Jan 20, 2011, 10:09 pm by foxbat Reason: 1
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>>8) & 0xff)
#define BLUE(a) (a & 0xff)

Don't forget that the 'base' parameter to strtol is 16.
Home of the Nokia QVGA TFT LCD hacks: http://andybrown.me.uk

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview