C Bitwise Operators
Bitwise operators are used to perform operations on the binary representation of integers. These operators include AND, OR, XOR, and more.
Common Bitwise Operators
- & - Bitwise AND
- | - Bitwise OR
- ^ - Bitwise XOR
- ~ - Bitwise NOT
- << - Left shift
- >> - Right shift
Example
#includeint main() { int a = 5, b = 3; printf("a & b: %d\n", a & b); // Bitwise AND printf("a | b: %d\n", a | b); // Bitwise OR printf("a ^ b: %d\n", a ^ b); // Bitwise XOR printf("~a: %d\n", ~a); // Bitwise NOT printf("a << 1: %d\n", a << 1); // Left shift printf("a >> 1: %d\n", a >> 1); // Right shift return 0; }
This program demonstrates how bitwise operators work in C.