I want to write a function getColor() that allows me to extract parts of a hexadecimal number entered as a long
The details are as follows:
//prototype and declarations
enum Color { Red, Blue, Green };
int getColor(const long hexvalue, enum Color);
//definition (pseudocode)
int getColor(const long hexvalue, enum Color)
{
switch (Color)
{
case Red:
; //return the LEFTmost value (i.e. return int value of xAB if input was 'xABCDEF')
break;
case Green:
; //return the 'middle' value (i.e. return int value of xCD if input was 'xABCDEF')
break;
default: //assume Blue
; //return the RIGHTmost value (i.e. return int value of xEF if input was 'xABCDEF')
break;
}
}
My 'bit twiddling' isn't what it used to be. I would appreciate some help on this.
[Edit] I changed the ordering of the color constants in the switch statements - no doubt any designers, CSS enthusiasts out there would have noticed that colors are defined (in the RGB scale) as RGB ;)