A program to explain bitwise operators
C Programming Language 010
The following code shows how to write a program to explain bitwise operators
Program
#include <stdio.h>
void main()
{
int a, b, c;
printf("Enter a,b values: ");
scanf("%d %d", &a, &b);
c = a & b;
printf("Bitwise AND result is\t %d\n", c);
c = a | b;
printf("Bitwise OR result is\t %d\n", c);
c = a ^ b;
printf("Bitwise ex-OR result is\t %d\n", c);
c = a << 2;
printf("Shift left result is\t %d\n", c);
c = a >> 2;
printf("Shift right result is\t %d\n", c);
c = ~a;
printf("Negation result is\t %d\n", c);
printf("\n");
}
Result
Enter a,b values: 4 5
Bitwise AND result is 4
Bitwise OR result is 5
Bitwise ex-OR result is 1
Shift left result is 16
Shift right result is 1
Negation result is -5
Last Updated on
Comments