Bit wise operator "and" use

Many programs uses bit wise operators to solve many problems.
Find given number is Even or Odd: "and" operator is used
example:
consider a decimal number 'a'
if a is 10 it's binary notation is 1010 the least significant bit is 0
if decimal number 10 is "and"ed with a one then answer will be a zero
if a is 3 it's binary notation is 11 the least significant bit is 1
if decimal number 3 is "and"ed with a one then answer will be 1
Hence conclusion that can be drawn will be
if a number is even it's "and" value with one is 0.
if a number is odd it's "and" value with one is 1.
number
Binary
and with 1
least significant bit
even or odd
10
1010
0001
0
even
3
0011
0001
1
odd
Code for this problem looks like
#include
#include
int main()
{
int number=10;
if(number&1)
printf("%d is a odd number",number);
else
printf("%d is a even number",number);
number=3;
if(number&1)
printf("%d is a odd number",number);
else
printf("%d is a odd number",number);
return 0;
}
OUTPUT :
the output of this program will be
10 is a even number
3 is a odd number
ALTERNATE
#include
#include
int main()
{
int number=10;
if(number%2)
printf("%d is a odd number",number);
else
printf("%d is a even number",number);
number=3;
if(number%2)
printf("%d is a odd number",number);
else
printf("%d is a odd number",number);
return 0;
}
output is
10 is a even number
3 is a odd number