Write a program to use bitwise AND operator b/w the 2 integers & display the results.

#include<stdio.h>
#include<conio.h>
int main()
{
	int a,b,c;
	printf("Read the integers from keyboard (a & b):-");
	scanf("%d %d",&a,&b);
	c=a & b;                   //AND operator//
	printf("The answer is (c)=%d",c);
	getch();
}

/* a=8 b=4 then output c=0
For mathematical calculation visit https://www.youtube.com/watch?v=_qqlY4Fyzo0 */

In the program, two integers a and b are read from the keyboard using the scanf() function. Then, bitwise AND operator & is applied to a and b, and the result is stored in the variable c. The printf() function is used to display the value of c on the screen.

The bitwise AND operator compares each corresponding bit of the two numbers and returns 1 if both bits are 1, otherwise, it returns 0.

In the example given, if a is 8 and b is 4, their corresponding binary values are 1000 and 0100, respectively. When the bitwise AND operator is applied to a and b, the result is 0000 which is equal to 0 in decimal representation. Hence, the output of the program will be The answer is (c)=0.

Thanks

Write a program to use bitwise AND operator b/w the 2 integers & display the results.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top