How do you convert from color HEX code to RGB in pure C using C library only (without C++ or templates)? The RGB struct may be like this:
An RGB value can be stored as in integer via 0xRRGGBB. Examples:
00 is hex for decimal 0, while ff is 255. 0 corresponds to 0.0 and 255 to 1.0. (Actually you didn't specify what the range is. I'm assuming 0.0 to 1.0.)
So with the above assumptions, you need to extract each component and divide by 255. Since it sounds a lot like a homework question, I'll just show you how you can do the red component.
int hex = 0x123456;
c.r = ((hex >> 16) & 0xff) / 255.0;
Each hex digit takes up 4 bits. So shift to the right by 16 bits (to move everything 4 digits to the right) to make 0xRRGGBB become 0xRR. Now you have the red component. (Just in case there is some data higher up in the integer, you can get rid of it by masking the data via & 0xff.)
If you are dealing with a string "#FFFFFF", then you'd first have to convert it to an integer for the above to work.