These are used for bit-wise Logical decision making.
i) Bit-wise Logical AND ( & )
ii) Bit-wise Logical OR ( | )
iii) Bit-wise Logical XOR ( ^ )
A1 | A2 | A1&A2 | A1|A2 | A1^A2 |
1 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 1 | 1 |
0 | 1 | 0 | 1 | 1 |
0 | 0 | 0 | 0 | 0 |
Eg1: int A=5, B=6;
then A&B is shown in below table
Values | Binary Form |
A=5 | 1 0 1 |
B=6 | 1 1 0 |
A&B = 4 | 1 0 0 |
Eg2: int A=5, B=6;
then A|B is shown in below table
Values | Binary Form |
A=5 | 1 0 1 |
B=6 | 1 1 0 |
A|B = 7 | 1 1 1 |
Eg3: int A=5, B=6;
then A^B is shown in below table
Values | Binary Form |
A=5 | 1 0 1 |
B=6 | 1 1 0 |
A^B = 3 | 0 1 1 |
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int A,B;
printf("Enter Values of A and B : ");
scanf("%d%d",&A,&b);
printf("\nA&B = %d",A&B);
printf("\nA|B = %d",A|B);
printf("\nA^B = %d",A^B);
getch();
}
Output:
Enter Values of A and B : 5 6
A&B = 4
A|B = 7
A^B = 3
No comments:
Post a Comment