Bitwise Operators
Bitwise operators perform operations on individual bits of integer types. The main bitwise operators are AND (&), OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>).
Bitwise AND Example:
#include <stdio.h>
int main() {
int a = 5; // 0101 in binary
int b = 3; // 0011 in binary
printf("Bitwise AND: %d\n", a & b); // 0001 in binary
return 0;
}
Output
Bitwise AND: 1
Bitwise OR Example:
#include <stdio.h>
int main() {
int a = 5; // 0101 in binary
int b = 3; // 0011 in binary
printf("Bitwise OR: %d\n", a | b); // 0111 in binary
return 0;
}
Output
Bitwise OR: 7