Velocity Reviews

Velocity Reviews (
-   C Programming (
-   -   Bit check using function check(var,pos) ((var)&(1<<pos)) (

prati 10-27-2012 05:25 PM

Bit check using function check(var,pos) ((var)&(1<<pos))
I have written one small program to check whether particular bit is set or not.

#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 ");


output: when entered position
0th(1<<0=0000 0001), bit value is 0
1st(1<<1=0000 0010), bit value is 2
2nd(1<<2=0000 0100), bit value is 4
3rd1<<3=0000 1000), bit value is 8
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?what check(var,pos) returns?

All times are GMT. The time now is 10:14 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.