Tuesday 24 July 2012

even or odd using bitwise AND

/*Program to check whether a given number is even or odd using bitwise AND */
int main()
{
int n;
//mask having least significant bit 1 and other bits are 0
int msk=0x1;
//Accept any number
printf("Enter a number:\n");

scanf("%d",&n);


//A number will be odd if its least significant bit
//i.e the right most bit is 1
//A number will be even if its least significant bit is 0

if((n & msk) ==0)
{
printf("Number is even\n");

}

else
{
printf("Number is odd");
}
}
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: