Originally Posted by
iMalc
This sounds to me more like a palette approach is asked for than a flag per colour. I'd therefore just use a lookup table.
Whats a lookup table?
So basically we don't or rather cannot assign values or data to bits.
Just toggle between 0 and 1 and do some operation if any condition is satisfied?
Check my code please:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num=0;
char color;
color = 64;
char colormask;
colormask = 64;
printf("Enter a number.");
scanf("%d",&num);
switch(num)
{
case 0: //red
//colormask = 64; //1000000
if((color & colormask))
printf("Red");
break;
case 1: //orange
colormask = 32; //100000 or colormask=colormask >> 1
color = color >> 1;
//printf("%d",color);
if(color & colormask)
printf("Orange");
break;
case 2: //yellow
colormask = colormask >> 2; // 16
color = color >> 2;
if(color & colormask)
printf("yellow");
break;
}
return 0;
}