我想编写一个函数getColor(),它可以让我从输入为long的十六进制数中提取部分。
详细信息如下:
//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;
}
}
我的“位操作”技能已经不如以前了。我需要一些帮助。
[编辑] 我更改了switch语句中颜色常量的顺序 - 毫无疑问,任何设计师、CSS爱好者都会注意到颜色是按RGB比例定义的。