I have written one small program to check whether particular bit is set or not. But not getting proper value when i check for upper nibble.
#define check(var,pos) ((var)&(1<<pos))
void main()
{
int var=30;// in binary 0011 0000 that is its 4th and 5th bits are set;
int bit;
printf("enter position where we want to check whether bit is set or not ");
scanf("%d",&pos);
bit=check(var,pos);
printf("%d",bit);
getch();
}
output: when entered position 4th (1<<4 =0001 0000) , bit value is 16 and when entered position is 5th(1<<5=0010 0000), bit value is 0.
please let me know why it is so?I get the proper bit value when lower nibbles of var are set.