Hey
I'm writing a color class, and I want to have a constructor that can take in an unsigned int like 0x00FF00FF and interpret it as fully opaque green. I have code for that (I think it should work, could someone check it?):
rzb::color::color(unsigned int hex)
{
m_red = (hex & 0xff000000)/(0x00ffffff);
m_green = (hex & 0x00ff0000)/(0x0000ffff);
m_blue = (hex & 0x0000ff00)/(0x000000ff);
m_alpha = (hex & 0x000000ff);
}
The thing is, I'd like the user to also be able to give this input: 0x00FF00, and have that also be interpreted as opaque green (alpha value would be FF by default), but I can't figure out how to do that. Is there a way to check the length of a number passed as input (or some other algorithm to do what I want). I can't just compare the values, because 0xffffff (opaque white) comes out to 16,777,215, but 0x0000ffee (slightly transparent green) comes out to 65,518, a smaller value, even though it's the the larger form.