-2

I have the following colour values - 0xFFFF40, 0xFFFF20, 0xff5099.

I want to convert these C++ codes into RGB values, how would I need to go about doing this?

Thanks

Edit: I would basically want to store these values in 3 different unsigned shorts:

unsigned short red;
unsigned short green;
unsigned short blue;
phs
  • 10,687
  • 4
  • 58
  • 84
Danny
  • 9,199
  • 16
  • 53
  • 75
  • The color value `0xff5099` stands for a red value of `ff`, a green value of `50` and a blue value of `99`, what else do you need? – Oswald Mar 28 '13 at 22:49
  • Could you elaborate on how you want them stored when you're done converting and how you have them stored as-is? – 2to1mux Mar 28 '13 at 22:50
  • hmm... I didn't know about that. Can I can ask does the '0x' means anything then? – Danny Mar 28 '13 at 22:51

1 Answers1

14

You can get each of the channels by masking them out individually:

// Original color
std::size_t color = 0xFFFF40;
std::size_t red   = (color & 0xff0000) >> 16;
std::size_t green = (color & 0x00ff00) >> 8;
std::size_t blue  = (color & 0x0000ff);
Dan Lecocq
  • 3,383
  • 25
  • 22