C program using bitwise AND (&)

Ex: write a C program to perform bitwise AND operation of two intiger's. How to write C Program to perform AND operation of two intiger's. C program to perform AND operation of two intiger's.

Input from user:

a=5 , b=15;

Expected Output:

After performing AND operation the output is: 5






  Logic to perform AND operation of the two intiger's :


First you need to know how  AND operator works.


  • The result of AND is 1 only if both bits are 1. Otherwise result is 0.


1. We take two intiger numbers a=5 and b=15.

2. The binary representation  of  a & b is:

       a=      0000 0101
       b=      0000 1111
---------------------------------
  a&b=      0000 0101 =5

3. After performing AND operation 8 bit binary representation is 0000 0101 which is 5 in decimal.

4. So output of the program is  5.





  C program using bitwise AND (&):


#include<stdio.h>
void main()
{
int a=5, b=15;

printf("After performing AND operation the output is:%d",a&b);

}

Above program shows the following output:


C program using bitwise AND, Write a C program to perform


No comments:

Post a Comment

If you have any doubts, please discuss here...👇